diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6b372bae..1bc86af6 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -217,6 +217,9 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->post("retail-endorsement-save", "EmployeeController::retailendorsementsave"); $routes->get("getTPADataVariationReport/(:num)", "EmployeeController::getTPADataVariationReport/$1"); $routes->get("bulkGenerateEcardAndStoreinS3", "EmployeeController::bulkGenerateEcardAndStoreinS3"); + $routes->get('clearCdSession', 'EmployeeController::clearCdSession'); + $routes->get('checkSessionStatus', 'EmployeeController::checkSessionStatus'); + }); @@ -683,7 +686,8 @@ $routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($route // get insurer and policy type $routes->get("getPolicyTypeAndInsurer", "EmployeeRestController::getPolicyTypeAndInsurer"); - + $routes->get("downloadCdSplitUpFile", "EmployeeRestController::downloadCdSplitUpFile"); + $routes->get("getExcelFileErrors/(:any)", "EmployeeController::getExcelFileErrors/$1"); }); $routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index c16c20eb..8ba51997 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -3611,194 +3611,6 @@ class ClientController extends AdminController } } - // public function enrollmentGMCDisplayValueTransform() - // { - // $data = []; - - // if ($this->request->getPost("waiverofpreexistingdiseases_display")) { - // $data['Waiver of Pre-existing Diseases'] = $this->request->getPost("waiverofpreexistingdiseases"); - // } - - // if ($this->request->getPost("waiverof1234thyearexclusions_display")) { - // $data['Waiver of 1, 2, 3 & 4th year Exclusions'] = $this->request->getPost("waiverof1,2,3&4thyearexclusions"); - // } - - // if ($this->request->getPost("waiverof30dayswaitingperiod_display")) { - // $data['Waiver of 30 days waiting period'] = $this->request->getPost("waiverof30dayswaitingperiod"); - // } - - // if ($this->request->getPost("suminsuredenhancement_display")) { - // $data['Sum Insured Enhancement'] = $this->request->getPost("suminsuredenhancement"); - // } - - // if ($this->request->getPost("waiver_of_90_days_waiting_period_display")) { - // $data['Waiver of 90 Days Waiting Period'] = $this->request->getPost("waiver_of_90_days_waiting_period"); - // } - - // if ($this->request->getPost("waiver_of_other_waiting_periods_display")) { - // $data['Waiver of Other Waiting Periods'] = $this->request->getPost("waiver_of_other_waiting_periods"); - // } - - // if ($this->request->getPost("maternity_benefit_display")) { - // $data['Maternity Benefit'] = $this->request->getPost("maternity_benefit"); - // } - - // if ($this->request->getPost("9monthwaitingperiodwaived_display")) { - // $data['9-month waiting Period - waived'] = $this->request->getPost("9monthwaitingperiodwaived"); - // } - - // if ($this->request->getPost("maternitycoverage_display")) { - // $data['Maternity Coverage'] = $this->request->getPost("maternitycoverage"); - // } - - // if ($this->request->getPost("twindelivery_display")) { - // $data['Twin Delivery'] = $this->request->getPost("twindelivery"); - // } - - // if ($this->request->getPost("well_baby_well_mother_expenses_display")) { - // $data['Well baby / Well Mother Expenses'] = $this->request->getPost("well_baby_well_mother_expenses"); - // } - - // if ($this->request->getPost("preandpostnatal_display")) { - // $data['Pre and Post natal'] = $this->request->getPost("preandpostnatal"); - // } - - // if ($this->request->getPost("infertility_treatment_coverage_display")) { - // $data['Infertility Treatment Coverage'] = $this->request->getPost("infertility_treatment_coverage"); - // } - - // if ($this->request->getPost("babyday1cover_display")) { - // $data['Baby Day 1 Cover'] = $this->request->getPost("babyday1cover"); - // } - - // if ($this->request->getPost("coverfromthedateofjoining_display")) { - // $data['Cover from the date of Joining'] = $this->request->getPost("coverfromthedateofjoining"); - // } - - // if ($this->request->getPost("mid_term_addition_of_new_born_newly_wedded_spouse_display")) { - // $data['Mid Term Addition of New Born / Newly Wedded Spouse'] = $this->request->getPost("mid_term_addition_of_new_born_newly_wedded_spouse"); - // } - - // if ($this->request->getPost("prehospitalizationcover_display")) { - // $data['Pre Hospitalization Cover'] = $this->request->getPost("prehospitalizationcover"); - // } - - // if ($this->request->getPost("posthospitalizationcover_display")) { - // $data['Post Hospitalization Cover'] = $this->request->getPost("posthospitalizationcover"); - // } - - // if ($this->request->getPost("congenitaldiseasesinternal_display")) { - // $data['Congenital Diseases - Internal'] = $this->request->getPost("congenitaldiseasesinternal"); - // } - - // if ($this->request->getPost("congenitaldiseasesexternal_display")) { - // $data['Congenital Diseases - External'] = $this->request->getPost("congenitaldiseasesexternal"); - // } - - // if ($this->request->getPost("copayzonewisecopay_display")) { - // $data['Co-Pay/Zone wise Co Pay'] = $this->request->getPost("copayzonewisecopay"); - // } - - // if ($this->request->getPost("roomrentlimit_display")) { - // $data['Room Rent Limit'] = $this->request->getPost("roomrentlimit"); - // } - - // if ($this->request->getPost("icu_limit_display")) { - // $data['ICU Limit'] = $this->request->getPost("icu_limit"); - // } - - // if ($this->request->getPost("proportionatedeductionclause_display")) { - // $data['Proportionate Deduction Clause'] = $this->request->getPost("proportionatedeductionclause"); - // } - - // if ($this->request->getPost("ailmentcapping_display")) { - // $data['Ailment capping'] = $this->request->getPost("ailmentcapping"); - // } - - // if ($this->request->getPost("ailment_capping_details_display")) { - // $data['Ailment capping Details'] = $this->request->getPost("ailment_capping_details"); - // } - - // if ($this->request->getPost("corporatebuffer_display")) { - // $data['Corporate Buffer'] = $this->request->getPost("corporatebuffer"); - // } - - // if ($this->request->getPost("non_admissible_contingency_corporate_buffer_display")) { - // $data['Non-Admissible / Contingency Corporate Buffer'] = $this->request->getPost("non_admissible_contingency_corporate_buffer"); - // } - - // if ($this->request->getPost("ambulancecharges_display")) { - // $data['Ambulance Charges'] = $this->request->getPost("ambulancecharges"); - // } - - // if ($this->request->getPost("airambulance_display")) { - // $data['Air Ambulance'] = $this->request->getPost("airambulance"); - // } - - // if ($this->request->getPost("reasonableandcustomarycharges_display")) { - // $data['Reasonable and Customary Charges'] = $this->request->getPost("reasonableandcustomarycharges"); - // } - - // if ($this->request->getPost("daycaretreatment_display")) { - // $data['Day Care Treatment'] = $this->request->getPost("daycaretreatment"); - // } - - // if ($this->request->getPost("lasiksurgery_display")) { - // $data['Lasik Surgery'] = $this->request->getPost("lasiksurgery"); - // } - - // if ($this->request->getPost("ayushtreatmentcover_display")) { - // $data['AYUSH treatment cover'] = $this->request->getPost("ayudhtreatmentcover"); - // } - - // if ($this->request->getPost("moderntreatmentsasperirdai_display")) { - // $data['Modern treatments as per IRDAI'] = $this->request->getPost("moderntreatmentsasperirdai"); - // } - - // if ($this->request->getPost("opd_treatment_display")) { - // $data['OPD Treatment'] = $this->request->getPost("opd_treatment"); - // } - - // if ($this->request->getPost("days_of_discharge_display")) { - // $data['Claim Intimation Clause'] = $this->request->getPost("days_of_discharge"); - // } - - // if ($this->request->getPost("days_from_dod_display")) { - // $data['Claim Submission'] = $this->request->getPost("days_from_dod"); - // } - - // if ($this->request->getPost("terrorism_display")) { - // $data['Terrorism'] = $this->request->getPost("terrorism"); - // } - - // if ($this->request->getPost("widower_cover_display")) { - // $data['Widower Cover'] = $this->request->getPost("widower_cover"); - // } - - // if ($this->request->getPost("breavement_cover_display")) { - // $data['Breavement Cover'] = $this->request->getPost("breavement_cover"); - // } - - // if ($this->request->getPost("special_condition_display_value")) { - - // $specialConditionKeyValue = $this->request->getPost("special_condition_display_value") ?? []; - // $specialConditionKeyValue = json_decode($specialConditionKeyValue, true); - - // if (is_array($specialConditionKeyValue) && count($specialConditionKeyValue) > 0) { - // $mergedArray = array_merge(...array_map(fn($item) => (array) $item, $specialConditionKeyValue)); - // $data = array_merge($data, $mergedArray); - // } - // } - - // if(isset($data) && !empty($data)){ - // return $data; - // }else{ - // $data = []; - // return $data; - // } - - // } - public function enrollmentGMCDisplayValueTransform() { $data = []; @@ -3873,7 +3685,6 @@ class ClientController extends AdminController return $data; } - public function getterms() { $client_policy_id = $this->request->getVar('client_policy_id'); @@ -4034,94 +3845,6 @@ class ClientController extends AdminController } } - // public function enrollmentGPADisplayValueTransform() - // { - // $data = []; - - // if ($this->request->getPost("accidentalDeathBenefit_display")) { - // $data['Accidental Death Benefit'] = $this->request->getPost("accidentalDeathBenefit"); - // } - // if ($this->request->getPost("permanentTotalDisablement_display")) { - // $data['Permanent Total Disablement'] = $this->request->getPost("permanentTotalDisablement"); - // } - // if ($this->request->getPost("permanentPartialDisablement_display")) { - // $data['Permanent Partial Disablement'] = $this->request->getPost("permanentPartialDisablement"); - // } - // if ($this->request->getPost("temporaryTotalDisablementBenefit_display")) { - // $data['Temporary Total Disablement Benefit'] = $this->request->getPost("temporaryTotalDisablementBenefit"); - // } - // if ($this->request->getPost("medical_expenses_medical_extension_display")) { - // $data['Medical Expenses / Medical Extension (IPD)'] = $this->request->getPost("medical_expenses_medical_extension"); - // } - // if ($this->request->getPost("opd_treatment_cover_display")) { - // $data['OPD Treatment Cover'] = $this->request->getPost("opd_treatment_cover"); - // } - // if ($this->request->getPost("ambulanceCharges_display")) { - // $data['Ambulance Charges'] = $this->request->getPost("ambulanceCharges"); - // } - // if ($this->request->getPost("repatriation_of_mortal_remains_display")) { - // $data['Repatriation of Mortal Remains'] = $this->request->getPost("repatriation_of_mortal_remains"); - // } - // if ($this->request->getPost("childrenEducationWelfareFund_display")) { - // $data['Children Education Welfare Fund'] = $this->request->getPost("childrenEducationWelfareFund"); - // } - // if ($this->request->getPost("terrorism_display")) { - // $data['Terrorism'] = $this->request->getPost("terrorism"); - // } - // if ($this->request->getPost("worldwideCover_display")) { - // $data['Worldwide Cover'] = $this->request->getPost("worldwideCover"); - // } - // if ($this->request->getPost("family_transportation_benefits_display")) { - // $data['Family Transportation Benefits'] = $this->request->getPost("family_transportation_benefits"); - // } - // if ($this->request->getPost("fractures_dislocation_burns_display")) { - // $data['Fractures / Dislocation / Burns'] = $this->request->getPost("fractures_dislocation_burns"); - // } - // if ($this->request->getPost("coma_display")) { - // $data['Coma'] = $this->request->getPost("coma"); - // } - // if ($this->request->getPost("carriageofDeadBody_display")) { - // $data['Carriage of Dead Body'] = $this->request->getPost("carriageOfDeadBody"); - // } - // if ($this->request->getPost("compassionateVisitExpenses_display")) { - // $data['Compassionate Visit Expenses'] = $this->request->getPost("compassionateVisitExpenses"); - // } - // if ($this->request->getPost("travel_expenses_for_medical_treatment_display")) { - // $data['Travel expenses for Medical Treatment'] = $this->request->getPost("travel_expenses_for_medical_treatment"); - // } - // if ($this->request->getPost("daily_cash_allowance_display")) { - // $data['Daily cash Allowance'] = $this->request->getPost("daily_cash_allowance"); - // } - // if ($this->request->getPost("artifical_limb_and_prosthesis_display")) { - // $data['Artifical Limb and Prosthesis'] = $this->request->getPost("artifical_limb_and_prosthesis"); - // } - // if ($this->request->getPost("animalSnakeInsectBite_display")) { - // $data['Animal/Snake/Insect Bite'] = $this->request->getPost("animalSnakeInsectBite"); - // } - // if ($this->request->getPost("air_ambulance_display")) { - // $data['Air Ambulance'] = $this->request->getPost("air_ambulance"); - // } - - // if ($this->request->getPost("gpa_special_condition_display_value")) { - - // $specialConditionKeyValue = $this->request->getPost("gpa_special_condition_display_value") ?? []; - // $specialConditionKeyValue = json_decode($specialConditionKeyValue, true); - - // if (is_array($specialConditionKeyValue) && count($specialConditionKeyValue) > 0) { - // $mergedArray = array_merge(...array_map(fn($item) => (array) $item, $specialConditionKeyValue)); - // $data = array_merge($data, $mergedArray); - // } - // } - // // print_r($data); die; - - // if (isset($data) && !empty($data)) { - // return $data; - // } else { - // $data = []; - // return $data; - // } - // } - public function enrollmentGPADisplayValueTransform() { $data = []; @@ -6614,6 +6337,8 @@ class ClientController extends AdminController public function sendextraparam() { + // $cd = $this->view_Deposit(2, 'rest', ['client_id' => 58, 'cd_ac_pk' => 94]); + // dd($cd); // $return = db_connect()->table('jobs')->where('id', 1677)->get()->getRowArray(); // $return = $this->updatePolicyTransactionDataWhileClinetPolicyUpdate(json_decode($data['payload'], true)); // dd($return); @@ -6644,8 +6369,8 @@ class ClientController extends AdminController // $response = $ticketServiceController->tpaClaimDumpImporter(["file_id" => 48]); //vidal // $response = $ticketServiceController->tpaClaimDumpImporter(["file_id" => 53]); //icici // $response = $ticketServiceController->tpaClaimDumpImporter(["file_id" => 54]); //mediassist - // $response = $ticketServiceController->tpaClaimDumpToTicketMasterImporters(["file_id" => 48]); - // $response = $ticketServiceController->tpaClaimDumpToTicketMasterImporters(["file_id" => 48]); + // $response = $ticketServiceController->tpaClaimDumpToTicketMasterImporters(["file_id" => 48]); //vidal + // $response = $ticketServiceController->tpaClaimDumpToTicketMasterImporters(["file_id" => 54]); //mediassist // dd($response); // ---------- TICKET CONTROLLER -------------------------------------------------------------------------------- diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 8d75b095..f6cfb67a 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -209,24 +209,23 @@ class EmpDataServiceController extends BaseController //check CD amt insufficient only insurer, not tpa // DO NOT REMOVE THIS if($export_data['insurer_or_tpa'] == 'insurer') { - if (!empty($cash_balance)) { - clear_cd_balance_session(); - if ((int) $cash_balance['balance'] == (int) $totals) { - $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.'); - $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount. CASH BALANCE : {balance} and TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]); - - $cd_session_data = json_encode(['cd_balance' => false, 'cd_amount' => $cash_balance['balance'], 'excel_file_amt' => $totals]); - session()->set('cd_balance_info', $cd_session_data); - session()->set('cd_balance', false); - - $hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']); - $session_data = json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]); - session()->set('hr_data', $session_data); - - }else{ - session()->set('cd_balance', true); - - } + if ((int) $cash_balance['balance'] < (int) $totals) { + clear_cd_balance_session(); // Clear old junk first + + $cd_session_data = json_encode([ + 'cd_balance' => false, + 'cd_amount' => $cash_balance['balance'], + 'excel_file_amt' => $totals + ]); + + session()->set('cd_balance_info', $cd_session_data); + session()->set('cd_balance', 'insufficient'); // Use a string status for clarity + + $hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']); + session()->set('hr_data', json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data])); + }else{ + session()->set('cd_balance', 'sufficient'); // Use a string status for clarity + session()->set('cd_balance_info', null); } } @@ -2195,6 +2194,7 @@ class EmpDataServiceController extends BaseController 'event_name' => $file['event_type'], 'policy_name' => $policy_name['policy_name'], 'user_id' => $user_id, + 'file_id' => $file_id, ]]); $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [ @@ -3378,6 +3378,7 @@ class EmpDataServiceController extends BaseController 'event_name' => $file['event_type'], 'policy_name' => $policy_name['policy_name'], 'user_id' => $user_id, + 'file_id' => $file_id, ]]); $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [ @@ -3889,6 +3890,7 @@ class EmpDataServiceController extends BaseController 'event_name' => $file['event_type'], 'policy_name' => $policy_name['policy_name'], 'user_id' => $user_id, + 'file_id' => $file_id, ]]); $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [ @@ -4373,7 +4375,8 @@ class EmpDataServiceController extends BaseController 'updated_by' => $arrayData['user_id'], 'event_name' => $arrayData['event_name'], 'is_active' => 1, - 'cd_ac_pk' => $cd_ac_pk['cd_ac_pk'] + 'cd_ac_pk' => $cd_ac_pk['cd_ac_pk'], + 'file_id' => $arrayData['file_id'], ]; $response = DepositHelper::saveDeposit($data, $arrayData['user_id']); @@ -4510,7 +4513,8 @@ class EmpDataServiceController extends BaseController 'updated_by' => $arrayData['user_id'], 'event_name' => $arrayData['event_name'], 'is_active' => 1, - 'cd_ac_pk' => $policy_data['cd_ac_pk'] + 'cd_ac_pk' => $policy_data['cd_ac_pk'], + 'file_id' => $arrayData['file_id'], ]; DepositHelper::saveDeposit($data, $arrayData['user_id']); @@ -4540,7 +4544,8 @@ class EmpDataServiceController extends BaseController 'updated_by' => $arrayData['user_id'], 'event_name' => $arrayData['event_name'], 'is_active' => 1, - 'cd_ac_pk' => $policy_data['cd_ac_pk'] + 'cd_ac_pk' => $policy_data['cd_ac_pk'], + 'file_id' => $arrayData['file_id'], ]; DepositHelper::saveDeposit($data, $arrayData['user_id']); @@ -4652,7 +4657,8 @@ class EmpDataServiceController extends BaseController 'updated_by' => $arrayData['user_id'], 'event_name' => $arrayData['event_name'], 'is_active' => 1, - 'cd_ac_pk' => $insurer_id['cd_ac_pk'] + 'cd_ac_pk' => $insurer_id['cd_ac_pk'], + 'file_id' => $arrayData['file_id'], ]; $response = DepositHelper::saveDeposit($data, $arrayData['user_id']); @@ -5418,7 +5424,7 @@ class EmpDataServiceController extends BaseController $this->myLogger->logme("error", "Policy transaction inserted successfully: " . json_encode(['insert_id' => $insert_id])); //do not remove this commented item - $coShareDetails = $this->ConstructPTShareData($policy_data, $insert_id, $params, $lead_data); + $coShareDetails = $this->ConstructPTShareData($policy_data, $insert_id, $params, $lead_data, $params['action_type']); $pt_co_share_id = $this->PTCOShareDetailsModel->insert($coShareDetails); $this->myLogger->logme("error", "PT Co share data inserted successfully: " . json_encode(['pt_co_share_id' => $pt_co_share_id])); @@ -5550,7 +5556,46 @@ class EmpDataServiceController extends BaseController return $policyTransactionData; } - private function ConstructPTShareData($policy_data, $pt_id, $params, $lead_data) + private function ConstructPTShareData($policy_data, $pt_id, $params, $lead_data, $action_type) + { + $policyTypeModel = new PolicyTypeModel(); + $policy_type_data = $policyTypeModel->where('is_active', 1)->where('id', $policy_data['policy_type_id'])->first(); + + // Determine if we should negate the values + $multiplier = (strtolower($action_type) === 'deletion') ? -1 : 1; + + $coShareData = [ + 'pt_id' => $pt_id, + 'insurer_id' => $policy_data['insurer_id'], + 'insurer_branch_id' => $policy_data['insurer_branch_id'], + 'bp_amt' => ($params['base_premium'] ?? 0) * $multiplier, + 'cop_amt' => ($params['base_premium'] ?? 0) * $multiplier, + 'bp_gst_amt' => ($params['gst'] ?? 0) * $multiplier, + 'bp_sgst' => 9, // Usually tax percentages remain positive, but multiply if this is an amount + 'bp_cgst' => 9, + 'co_share_type' => 1, + 'co_share_per' => 100, + 'standerd_bp_per' => $policy_type_data['ebp'], + 'pt_policy_issue_date' => $params['policy_issue_date'] ?? null, + 'amount' => (($params['base_premium'] ?? 0) + ($params['gst'] ?? 0)) * $multiplier, + ]; + + if(isset($policy_data['gst']) && $policy_data['gst'] != null){ + $coShareData['bp_igst'] = $policy_data['gst'] ?? 0; + $coShareData['bp_sgst'] = 0; + $coShareData['bp_cgst'] = 0; + } + + // Calculate exp_amt logic + $agreed_per = $lead_data['agreed_percentage'] ?? $policy_type_data['ebp'] ?? 0; + $coShareData['exp_amt'] = ((($params['base_premium'] ?? 0) * $agreed_per) / 100) * $multiplier; + + $this->myLogger->logme("error", "Constructed PT co-share data: " . json_encode($coShareData)); + + return $coShareData; + } + + private function ConstructPTShareDataOld($policy_data, $pt_id, $params, $lead_data, $action_type = null) { $policyTypeModel = new PolicyTypeModel(); $policy_type_data = $policyTypeModel->where('is_active', 1)->where('id', $policy_data['policy_type_id'])->first(); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index c1d2d717..db0468ae 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -445,6 +445,7 @@ class EmployeeController extends AdminController batch_files.amount, batch_files.status, batch_files.client_branch_id, + DATE_FORMAT(batch_files.policy_issue_date, '%d/%m/%Y') AS policy_issue_date, CASE WHEN batch_files.status IN ('partially success', 'in-progress-partially', 'failed-7') @@ -4584,6 +4585,20 @@ class EmployeeController extends AdminController } + public function clearCdSession() + { + clear_cd_balance_session(); + return $this->response->setJSON(['status' => 'cleared']); + } + + public function checkSessionStatus() + { + // Uses your existing get_cd_balance() helper + $data = get_cd_balance(); + + // Return as JSON so JavaScript can read it + return $this->response->setJSON($data); + } } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index f18b0a1a..e60cc86a 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -40,6 +40,7 @@ use App\Models\HRAccessControlModel; use App\Models\InsurerModel; use App\Models\HrFileUploadModel; use App\Models\EmployeeRetailPolicy; +use App\Models\BatchFileModel; @@ -100,6 +101,7 @@ class EmployeeRestController extends AdminController protected $hrFileUploadModel; protected $ticketMailTemplateModel; protected $employeeRetailPolicy; + protected $batchFileModel; public function __construct() @@ -134,6 +136,7 @@ class EmployeeRestController extends AdminController $this->insurerModel = new InsurerModel(); $this->hrFileUploadModel = new HrFileUploadModel(); $this->ticketMailTemplateModel = new TicketMailTemplateModel(); + $this->batchFileModel = new BatchFileModel(); } @@ -5379,6 +5382,35 @@ class EmployeeRestController extends AdminController return $claim_status_data_id; } + public function downloadCdSplitUpFile() + { + try { + + $file_id = $this->request->getGet('id'); + + // Find record + $record = $this->batchFileModel->where('id', $file_id)->first();; + if (!$record) { + $data['message'] = 'File record not found'; + return view('errors/404', $data); + } + + $uploadPath = WRITEPATH . 'uploads/import_excel/'; + $filePath = $uploadPath . $record['file_name']; + + if (!file_exists($filePath)) { + // return $this->failNotFound("File not found on server"); + $data['message'] = 'The Physical File Not Found'; + return view('errors/404', $data); + } + + // Force file download + return $this->response->download($filePath, null)->setFileName($record['file_name']); + } catch (\Exception $e) { + $data['message'] = 'File record not found'; + return view('errors/404', $data); + } + } } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index dc6538d4..7017dd07 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -497,6 +497,9 @@ class MasterController extends AdminController { $this->myLogger->logme('error','Edit Insurer general info function called'); + $postData = $this->request->getPost(); + $logoFile = $this->request->getFile('insurer_logo'); + $rules = [ 'name' => [ 'rules' => 'required', @@ -513,22 +516,30 @@ class MasterController extends AdminController ] ], 'insurer_logo' => [ - 'rules' => 'if_exist|is_image[insurer_logo]|max_size[insurer_logo,200]|ext_in[insurer_logo,jpg,jpeg,png]', + 'rules' => 'permit_empty|is_image[insurer_logo]|max_size[insurer_logo,200]|ext_in[insurer_logo,jpg,jpeg,png]', 'errors' => [ 'is_image' => 'The uploaded file must be an image', 'max_size' => 'File size should not exceed 200 KB', - 'ext_in' => 'Allowed file types: jpg, jpeg, png', + 'ext_in' => 'Only JPG, JPEG, and PNG files are allowed.', ] ], ]; - if (!$this->validate($rules)) { - return $this->response->setStatusCode(400)->setJSON([ - 'status' => false, - 'message' => 'Input validation failed', - 'code' => 400, - 'errors' => $this->validator->getErrors() - ]); + if (!$this->validateData($postData, $rules)) { + $errors = $this->validator->getErrors(); + + $mainMessage = 'Input validation failed'; + + if (isset($errors['insurer_logo']) && (strpos($errors['insurer_logo'], 'Security') !== false || strpos($errors['insurer_logo'], 'Forbidden') !== false)) { + $mainMessage = 'File upload rejected: Security policy violation.'; + } + + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => $mainMessage, // This will change based on the error + 'code' => 400, + 'errors' => $this->validator->getErrors() + ]); } $uploadFilePath = ROOTPATH . 'public/uploads/logo/'; diff --git a/app/Controllers/TicketServiceController.php b/app/Controllers/TicketServiceController.php index 14c1b19a..602f0708 100644 --- a/app/Controllers/TicketServiceController.php +++ b/app/Controllers/TicketServiceController.php @@ -9,6 +9,11 @@ use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use Kint\Kint; use App\Libraries\TpaClaimsImportFactory; use App\Libraries\TPAClaimsImportServices\FhplClaimImportService; +use App\Libraries\TPAClaimsImportServices\MediAssistClaimImportService; +use App\Libraries\TPAClaimsImportServices\AbhiClaimImportService; +use App\Libraries\TPAClaimsImportServices\RcareClaimImportService; +use App\Libraries\TPAClaimsImportServices\VidalClaimImportService; +use App\Libraries\TPAClaimsImportServices\IciciClaimImportService; use App\Libraries\TPAClaimsImportServices\BaseTpaClaimImportService; use App\Models\ClaimDumpFileModel; @@ -1858,23 +1863,21 @@ class TicketServiceController extends BaseController public function tpaClaimDumpImporter($params) { - try { + $file_id = $params['file_id'] ?? null; // Move outside try to ensure catch can see it - $file_id = $params['file_id'] ?? null; - $file_path = WRITEPATH . 'uploads/claim_dump_excel/'; + try { + $file_path = WRITEPATH . 'uploads' . DIRECTORY_SEPARATOR . 'claim_dump_excel' . DIRECTORY_SEPARATOR; if (!$file_id) { return ['status' => false, 'message' => 'File ID is missing']; } - $fileData = $this->claimDumpFileModel->where('id', $file_id)->first(); - + $fileData = $this->claimDumpFileModel->find((int)$file_id); if (!$fileData) { return ['status' => false, 'message' => 'Invalid file ID. No file data found']; } $file_full_path = $file_path . $fileData['file_name']; - if (!is_file($file_full_path)) { return ['status' => false, 'message' => 'Claim dump file not found']; } @@ -1882,106 +1885,97 @@ class TicketServiceController extends BaseController $handler = TpaClaimsImportFactory::make($fileData['tpa_id'] ?? 0); $result = $handler->runTpaClaimDumpInsert($file_full_path, $file_id); - // ---------- Prepare update data ---------- - $data = []; - if (!empty($result['status']) && $result['status'] === true) { - $data['status'] = 'success'; - $data['reason'] = null; + Jobs::addJob(['job_name' => 'tpaClaimDumpToTicketMasterImporters', 'payload' => ['file_id' => $file_id]]); } else { - $data['status'] = 'failed'; - - $errorMessage = $result['message'] ?? 'Unknown import error'; - - $reason = [ - 'error_summary' => array_count_values([5]), - 'error_data' => $errorMessage - ]; - - $data['reason'] = json_encode($reason, JSON_UNESCAPED_UNICODE); - } - - // dd($data); - // ---------- Update DB ---------- - $sql = "UPDATE claim_dump_files SET status = ?, reason = ? WHERE id = ?"; - - $updated = db_connect()->query( - $sql, - [ - $data['status'] ?? null, - $data['reason'] ?? null, - $file_id - ] - ); - - if (!$updated) { - $this->myLogger->logme('error', 'Claim dump file update failed for file_id: ' . $file_id); - } - - dd(db_connect()->getLastQuery()->getQuery()); - - if(!empty($result['status']) && $result['status'] === true){ - $r = Jobs::addJob(['job_name' => 'tpaClaimDumpToTicketMasterImporters', 'payload' => ['file_id' => $file_id]]); + // FORCE FAIL LOGIC + $this->markAsFailed($file_id, $result['message'] ?? 'System error contact admin', $fileData['created_by'] ?? null); } return $result; - } catch (\Throwable $th) { + $this->myLogger->logme("error", 'TPA_CLAIM_IMPORTER_JOB : ' . $th->getMessage()); - $this->myLogger->logme( - "error", - 'TPA_CLAIM_IMPORTER_JOB : ' . - $th->getMessage() . ' | Line: ' . $th->getLine() - ); + if (!empty($file_id)) { + $this->markAsFailed($file_id, 'System error contact admin'); + } return [ 'status' => false, 'message' => 'TPA Claim dump import failed', - 'error_data' => [ - 'message' => $th->getMessage(), - 'file' => $th->getFile(), - 'line' => $th->getLine(), - 'trace' => $th->getTraceAsString() - ] + 'error_data' => $th->getMessage() ]; } } + private function markAsFailed($file_id, $message, $user_id = null) + { + $reason = json_encode([ + 'error_summary' => [5 => 1], + 'error_data' => $message + ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + + $data = [ + 'status' => 'failed', + 'reason' => $reason, + 'updated_by' => $user_id + ]; + + // Using the direct update(id, data) method is often more reliable inside try/catch + return $this->claimDumpFileModel->update($file_id, $data); + } + public function tpaClaimDumpToTicketMasterImporters($params) { - try { + $file_id = $params['file_id'] ?? null; + $fileData = null; + + try { + if (!$file_id) { + return ['status' => false, 'message' => 'File ID is missing']; + } - $file_id = $params['file_id'] ?? null; $fileData = $this->claimDumpFileModel->where('id', $file_id)->first(); if (!$fileData) { - return ['status' => false, 'message' => 'Invalid file ID No file data found to import']; + return ['status' => false, 'message' => 'Invalid file ID. No file data found to import']; } $handler = TpaClaimsImportFactory::make($fileData['tpa_id'] ?? 0); $result = $handler->runTicketMasterInsert($params); + if (!empty($result['status']) && $result['status'] === true) { + // Success: Update the status to success + $this->claimDumpFileModel->update($file_id, [ + 'status' => 'success', + 'reason' => null + ]); + } else { + // Logic failure: The runTicketMasterInsert returned status false + $this->markAsFailed( + $file_id, + $result['message'] ?? 'System error contact admin', + $fileData['created_by'] ?? null + ); + } + return $result; - } catch (\Throwable $th) { + // Log the full error + $this->myLogger->logme("error", 'TICKET_MASTER_CLAIM_IMPORTER_JOB :' . $th->getMessage() . ' at line ' . $th->getLine()); - $this->myLogger->logme("error", 'TICKET_MASTER_CLAIM_IMPORTER_JOB :' .($th->getMessage() . ' --- ' . $th->getLine() . '----' . $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, - ]; + // CRITICAL: Even if the code crashes, try to mark the file as failed + if ($file_id) { + $this->markAsFailed($file_id, 'Fatal Crash: ' . $th->getMessage(), $fileData['created_by'] ?? null); + } return [ 'status' => false, 'message' => $th->getMessage(), - 'error_data' => json_encode($errorData, JSON_PRETTY_PRINT) + 'error_data' => [ + 'line' => $th->getLine(), + 'file' => $th->getFile() + ] ]; } } diff --git a/app/Helpers/DepositHelper.php b/app/Helpers/DepositHelper.php index 495797f3..05521df4 100755 --- a/app/Helpers/DepositHelper.php +++ b/app/Helpers/DepositHelper.php @@ -67,7 +67,8 @@ class DepositHelper 'balance' => $newBalance, // Include the new balance in the data array 'cd_ac_pk'=> isset($data['cd_ac_pk'])?$data['cd_ac_pk']:null, 'record_date' => $data['record_date'] ?? null, - 'policy_transaction_id' => $data['pt_id'] ?? null + 'policy_transaction_id' => $data['pt_id'] ?? null, + 'file_id' => $data['file_id'], ]; // Insert data and get the insert ID diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index efec7f1d..919fd49c 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -1108,6 +1108,7 @@ if (!function_exists('get_cd_balance')) { return [ 'has_cd_balance' => $session->has('cd_balance'), + 'cd_balance' => $session->get('cd_balance') ?? null, 'hr_data' => $session->get('hr_data') ?? [], 'cd_balance_info' => $session->get('cd_balance_info') ?? [], ]; diff --git a/app/Libraries/TPAClaimsImportServices/AbhiClaimImportService.php b/app/Libraries/TPAClaimsImportServices/AbhiClaimImportService.php index 21818613..1f9837b9 100644 --- a/app/Libraries/TPAClaimsImportServices/AbhiClaimImportService.php +++ b/app/Libraries/TPAClaimsImportServices/AbhiClaimImportService.php @@ -114,6 +114,8 @@ class AbhiClaimImportService extends BaseTpaClaimImportService // Misc 'diagnosis' => 'claim_description', 'healthcard_id' => 'tpa_no', + 'claim_type' => 'tpa_claim_type', + ]; protected $statusMapping = [ @@ -174,9 +176,7 @@ class AbhiClaimImportService extends BaseTpaClaimImportService } $ticketMasterModel = new TicketMasterModel(); - $ticketMasterModel->insertBatch($data); - - return true; + return $ticketMasterModel->insertBatch($data); } @@ -187,9 +187,7 @@ class AbhiClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_abhi'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -200,9 +198,7 @@ class AbhiClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_abhi'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -307,7 +303,7 @@ class AbhiClaimImportService extends BaseTpaClaimImportService if ($isduplicate) { $reason = "This claim already exists in our system."; - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } @@ -326,23 +322,15 @@ class AbhiClaimImportService extends BaseTpaClaimImportService if (!empty($employee_data)) { $item['emp_id'] = $employee_data['id'] ?? null; $item['emp_name'] = $employee_data['name'] ?? null; + $item['emp_code'] = $employee_data['emp_code'] ?? null; $item['emp_mail'] = $employee_data['email_corporate'] ?? null; $item['emp_mobile'] = $employee_data['mobile'] ?? null; $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; } else { - $reason = sprintf( - 'The policy number "%s" does not exist in our system. ' . - 'Details - Client ID: %s, Client Policy ID: %s, Employee Number: %s, Relationship: %s', - $row['insurer_policy_number'], - $file_data['client_id'], - $file_data['client_policy_id'], - $row['employee_number'], - $item['relationship'] - ); - - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $reason = 'This employee not exist in our system.'; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } diff --git a/app/Libraries/TPAClaimsImportServices/BaseTpaClaimImportService.php b/app/Libraries/TPAClaimsImportServices/BaseTpaClaimImportService.php index 1485dee2..d2b715cc 100644 --- a/app/Libraries/TPAClaimsImportServices/BaseTpaClaimImportService.php +++ b/app/Libraries/TPAClaimsImportServices/BaseTpaClaimImportService.php @@ -27,79 +27,49 @@ abstract class BaseTpaClaimImportService */ public function runTpaClaimDumpInsert(string $filePath, int $fileId): array { - $this->db->transStart(); + // 1. Start Transaction + $this->db->transBegin(); - $fileData = $this->claimDumpFileModel->where('id', $fileId)->first(); + try { + $fileData = $this->claimDumpFileModel->where('id', $fileId)->first(); - if (env('FHPL_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - $rows = $this->readExcelBySheetName($filePath, 'Claims&Preauth'); - } else if (env('R_CARE_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - $rows = $this->readExcelBySheetName($filePath, 'CL'); - // $AL = $this->readExcelBySheetName($filePath, 'AL'); - // $rows = array_merge($CL, $AL); - } else { - $rows = $this->readExcel($filePath); - } - // dd($rows); + // Determine sheet name logic... + if (env('FHPL_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { + $rows = $this->readExcelBySheetName($filePath, 'Claims&Preauth'); + } else if (env('R_CARE_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { + $rows = $this->readExcelBySheetName($filePath, 'CL'); + } else { + $rows = $this->readExcel($filePath); + } - if (empty($rows)) { - return ['status' => false, 'message' => 'Excel file contains no data or wrong file upload']; - } + if (empty($rows)) { + $this->db->transRollback(); // ROLLBACK BEFORE RETURN + return ['status' => false, 'message' => 'Excel file contains no data or wrong file upload']; + } - $tpaInsertData = $this->mapTPAData($rows, $fileId); - // dd($tpaInsertData); + $tpaInsertData = $this->mapTPAData($rows, $fileId); - if (empty($tpaInsertData)) { - return ['status' => false, 'message' => 'These records already exist in the system.']; - } + if (empty($tpaInsertData)) { + $this->db->transRollback(); // ROLLBACK BEFORE RETURN + return ['status' => false, 'message' => 'These records already exist in the system.']; + } - if (env('FHPL_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - $ClaimsDumpFhplModel = $this->db->table('claims_dump_fhpl'); - $return_res = $ClaimsDumpFhplModel->insertBatch($tpaInsertData); - } else if (env('R_CARE_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - $ClaimsDumpIciciModel = $this->db->table('claims_dump_reliance'); - $return_res = $ClaimsDumpIciciModel->insertBatch($tpaInsertData); - } else if (env('ICICI_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - $ClaimsDumpIciciModel = $this->db->table('claims_dump_icici'); - $return_res = $ClaimsDumpIciciModel->insertBatch($tpaInsertData); - } else if (env('ABHI_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - // $ClaimsDumpAbhiModel = $this->db->table('claims_dump_abhi'); - // $return_res = $ClaimsDumpAbhiModel->insertBatch($tpaInsertData); $return_res = $this->bulkInsertTPATable($tpaInsertData); - } else if (env('VIDAL_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - $ClaimsDumpVidalModel = $this->db->table('claims_dump_vidal'); - $return_res = $ClaimsDumpVidalModel->insertBatch($tpaInsertData); - } else if (env('MEDI_ASSIST_PRIMARY_KEY_CONSTANT') == $fileData['tpa_id']) { - $ClaimsDumpMediAssistModel = $this->db->table('claims_dump_medi_assist'); - $return_res = $ClaimsDumpMediAssistModel->insertBatch($tpaInsertData); - } else{ + if ($return_res !== true) { + $this->db->transRollback(); // ROLLBACK BEFORE RETURN + return ['status' => false, 'message' => 'TPA Import bulk insert failed']; + } + + // 2. Commit if everything is fine + $this->db->transCommit(); + return ['status' => true, 'message' => 'File uploaded successfully', 'record_count' => count($tpaInsertData)]; + + } catch (\Throwable $e) { + // 3. Rollback on any crash/exception + $this->db->transRollback(); + return ['status' => false, 'message' => 'System error : ' . $e->getMessage()]; } - - // $return_res = $this->bulkInsertTPATable($tpaInsertData); - - if (!$return_res) { - return ['status' => false, 'message' => 'TPA Import bulk insert failed']; - } - - $this->db->transComplete(); - - if ($this->db->transStatus() === false) { - - $error = $this->db->error(); - - $error_data = [ - 'message' => $error['message'] ?: 'Unknown DB error', - 'code' => $error['code'] ?? null, - 'last_query' => (string) $this->db->getLastQuery() - ]; - - // dd($error_data); - // unset($error_data['last_query']); - return ['status' => false, 'message' => 'TPA Import transaction failed', 'error_data' => $error_data]; - } - - return ['status' => true, 'message' => 'File uploaded successfully', 'record_count' => count($tpaInsertData ?? [])]; } /** @@ -107,34 +77,65 @@ abstract class BaseTpaClaimImportService */ public function runTicketMasterInsert(array $params): array { - $this->db->transStart(); + // 1. Start manual transaction + $this->db->transBegin(); - $file_id = $params['file_id']; + try { + $file_id = $params['file_id']; + $ticketMasterData = $this->mapClaimMasterData($file_id); - $ticketMasterData = $this->mapClaimMasterData($file_id); + // Check if mapping failed + if (!$ticketMasterData['status']) { + $this->db->transRollback(); // ALWAYS rollback before early return + return $ticketMasterData; + } - if (!$ticketMasterData['status']) { - return $ticketMasterData; + $message = ''; + $hasExecutedTask = false; + + // Process Mapped Data + if (!empty($ticketMasterData['mapped_array'])) { + $insert_res = $this->importClaimMaster($ticketMasterData['mapped_array']); + if (!$insert_res) { + $this->db->transRollback(); + return ['status' => false, 'message' => 'Ticket Master Claim bulk insert failed']; + } + $message .= 'Ticket Master Claim bulk insert success. '; + $hasExecutedTask = true; + } + + // Process Rejected Reasons + if (!empty($ticketMasterData['rejected_reason_array'])) { + $update_res = $this->updateTicketMasterRejectedReasonInTPATable($ticketMasterData['rejected_reason_array']); + if (!$update_res) { + $this->db->transRollback(); + return ['status' => false, 'message' => 'Updating rejected reasons failed']; + } + + $message .= empty($ticketMasterData['mapped_array']) + ? 'Those employees not in our system. ' + : 'Ticket Master Claim rejected reason updated successfully. '; + $hasExecutedTask = true; + } + + // If nothing was processed but no error occurred + if (!$hasExecutedTask) { + $this->db->transRollback(); + return ['status' => false, 'message' => 'No data found to process.']; + } + + // 2. Commit the transaction + $this->db->transCommit(); + return ['status' => true, 'message' => trim($message)]; + + } catch (\Throwable $th) { + // 3. Rollback on crash + $this->db->transRollback(); + return [ + 'status' => false, + 'message' => 'System error during Ticket Master Insert: ' . $th->getMessage() + ]; } - - $return_res = $this->importClaimMaster($ticketMasterData['mapped_array']); - - if(!$return_res){ - return ['status' => false, 'message' => 'Ticket Master Claim bulk insert failed']; - } - - $this->updateTicketMasterRejectedReasonInTPATable($ticketMasterData['rejected_reason_array']); - - $this->db->transComplete(); - - if ($this->db->transStatus() === false) { - return ['status' => false, 'message' => 'Ticket Master Claim bulk insert failed']; - } - - - - return ['status' => true, 'message' => 'Ticket Master Claim inserted successfully']; - } /** @@ -278,6 +279,7 @@ abstract class BaseTpaClaimImportService ->where('is_active', 1) ->where('file_id', $params['file_id']) ->where('ticket_id IS NULL') + ->where('master_reject_reason IS NULL') ->countAllResults(); $batch_size = 100; @@ -291,6 +293,7 @@ abstract class BaseTpaClaimImportService ->where('is_active', 1) ->where('file_id', $params['file_id']) ->where('ticket_id IS NULL') + ->where('master_reject_reason IS NULL') ->get() ->getResultArray(); @@ -308,6 +311,7 @@ abstract class BaseTpaClaimImportService 'employees.email_corporate AS emp_mail', 'employees.mobile AS emp_mobile', 'employees.name AS emp_name', + 'employees.emp_code AS emp_code', // insured employee 'insured.id AS insured_emp_id', diff --git a/app/Libraries/TPAClaimsImportServices/FhplClaimImportService.php b/app/Libraries/TPAClaimsImportServices/FhplClaimImportService.php index 72614418..58dd1282 100644 --- a/app/Libraries/TPAClaimsImportServices/FhplClaimImportService.php +++ b/app/Libraries/TPAClaimsImportServices/FhplClaimImportService.php @@ -177,10 +177,7 @@ class FhplClaimImportService extends BaseTpaClaimImportService // Payment 'cheque_no' => 'utr_details', 'uhid_no' => 'tpa_no', - - 'priority' => 1, - 'mode_of_intimation' => 5, - 'ticket_type_id' => 1, + 'claim_type' => 'tpa_claim_type', ]; protected $statusMapping = [ @@ -239,9 +236,7 @@ class FhplClaimImportService extends BaseTpaClaimImportService } $ticketMasterModel = new TicketMasterModel(); - $ticketMasterModel->insertBatch($data); - - return true; + return $ticketMasterModel->insertBatch($data); } @@ -252,9 +247,7 @@ class FhplClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_fhpl'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -265,9 +258,7 @@ class FhplClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_fhpl'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -372,7 +363,7 @@ class FhplClaimImportService extends BaseTpaClaimImportService if ($isduplicate) { $reason = "This claim already exists in our system."; - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } @@ -391,23 +382,15 @@ class FhplClaimImportService extends BaseTpaClaimImportService if (!empty($employee_data)) { $item['emp_id'] = $employee_data['id'] ?? null; $item['emp_name'] = $employee_data['name'] ?? null; + $item['emp_code'] = $employee_data['emp_code'] ?? null; $item['emp_mail'] = $employee_data['email_corporate'] ?? null; $item['emp_mobile'] = $employee_data['mobile'] ?? null; $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; } else { - $reason = sprintf( - 'The policy number "%s" does not exist in our system. ' . - 'Details - Client ID: %s, Client Policy ID: %s, Employee Number: %s, Relationship: %s', - $row['insurer_policy_number'], - $file_data['client_id'], - $file_data['client_policy_id'], - $row['employee_number'], - $item['relationship'] - ); - - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $reason = 'This employee not exist in our system.'; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } diff --git a/app/Libraries/TPAClaimsImportServices/IciciClaimImportService.php b/app/Libraries/TPAClaimsImportServices/IciciClaimImportService.php index b89221ae..f2717fd5 100644 --- a/app/Libraries/TPAClaimsImportServices/IciciClaimImportService.php +++ b/app/Libraries/TPAClaimsImportServices/IciciClaimImportService.php @@ -100,7 +100,8 @@ class IciciClaimImportService extends BaseTpaClaimImportService 'cheque_number' => 'utr_details', 'uhid' => 'tpa_no', - 'rejected_query_desc' => 'claim_description', + 'rejected_query_desc' => 'claim_description', + 'type_of_claim' => 'tpa_claim_type', ]; protected $statusMapping = [ @@ -168,9 +169,7 @@ class IciciClaimImportService extends BaseTpaClaimImportService } $ticketMasterModel = new TicketMasterModel(); - $ticketMasterModel->insertBatch($data); - - return true; + return $ticketMasterModel->insertBatch($data); } @@ -181,9 +180,7 @@ class IciciClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_icici'); - $builder->insertBatch($data); - - return true; + return $builder->upsertBatch($data, 'id'); } @@ -194,9 +191,7 @@ class IciciClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_icici'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -301,7 +296,7 @@ class IciciClaimImportService extends BaseTpaClaimImportService if ($isduplicate) { $reason = "This claim already exists in our system."; - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } @@ -320,23 +315,15 @@ class IciciClaimImportService extends BaseTpaClaimImportService if (!empty($employee_data)) { $item['emp_id'] = $employee_data['id'] ?? null; $item['emp_name'] = $employee_data['name'] ?? null; + $item['emp_code'] = $employee_data['emp_code'] ?? null; $item['emp_mail'] = $employee_data['email_corporate'] ?? null; $item['emp_mobile'] = $employee_data['mobile'] ?? null; $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; } else { - $reason = sprintf( - 'The policy number "%s" does not exist in our system. ' . - 'Details - Client ID: %s, Client Policy ID: %s, Employee Number: %s, Relationship: %s', - $row['insurer_policy_number'], - $file_data['client_id'], - $file_data['client_policy_id'], - $row['employee_number'], - $item['relationship'] - ); - - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $reason = 'This employee not exist in our system.'; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } diff --git a/app/Libraries/TPAClaimsImportServices/MediAssistClaimImportService.php b/app/Libraries/TPAClaimsImportServices/MediAssistClaimImportService.php index 7326567d..ad5a8657 100644 --- a/app/Libraries/TPAClaimsImportServices/MediAssistClaimImportService.php +++ b/app/Libraries/TPAClaimsImportServices/MediAssistClaimImportService.php @@ -49,7 +49,7 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService ["excel_column" => ["col_name" => "intimation_id", "col_index" => 30], "db_column" => "intimation_id"], ["excel_column" => ["col_name" => "intimation_date", "col_index" => 31], "db_column" => "intimation_date"], ["excel_column" => ["col_name" => "settled_date", "col_index" => 32], "db_column" => "settled_date"], - ["excel_column" => ["col_name" => "ClaimSource", "col_index" => 33], "db_column" => "claim_source"], + ["excel_column" => ["col_name" => "ClaimSource", "col_index" => 33], "db_column" => "ClaimSource"], ["excel_column" => ["col_name" => "claim_mode_of_rcpt", "col_index" => 34], "db_column" => "claim_mode_of_rcpt"], ["excel_column" => ["col_name" => "claim_type", "col_index" => 35], "db_column" => "claim_type"], ["excel_column" => ["col_name" => "claim_sub_type", "col_index" => 36], "db_column" => "claim_sub_type"], @@ -72,16 +72,16 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService ["excel_column" => ["col_name" => "hospital_state", "col_index" => 53], "db_column" => "hospital_state"], ["excel_column" => ["col_name" => "hospital_pincode", "col_index" => 54], "db_column" => "hospital_pincode"], ["excel_column" => ["col_name" => "hospital_address", "col_index" => 55], "db_column" => "hospital_address"], - ["excel_column" => ["col_name" => "Clinic_DoctorName_Hospital", "col_index" => 56], "db_column" => "clinic_doctorname_hospital"], - ["excel_column" => ["col_name" => "OPD_pincode", "col_index" => 57], "db_column" => "opd_pincode"], - ["excel_column" => ["col_name" => "payable_amount_OPD_Consultation", "col_index" => 58], "db_column" => "payable_amount_opd_consultation"], - ["excel_column" => ["col_name" => "payable_amount_Dental", "col_index" => 59], "db_column" => "payable_amount_dental"], - ["excel_column" => ["col_name" => "payable_amount_Diagnostics", "col_index" => 60], "db_column" => "payable_amount_diagnostics"], - ["excel_column" => ["col_name" => "payable_amount_Other", "col_index" => 61], "db_column" => "payable_amount_other"], - ["excel_column" => ["col_name" => "payable_amount_Pharmacy", "col_index" => 62], "db_column" => "payable_amount_pharmacy"], - ["excel_column" => ["col_name" => "payable_amount_Vaccination", "col_index" => 63], "db_column" => "payable_amount_vaccination"], - ["excel_column" => ["col_name" => "payable_amount_Miscellaneous_Charges", "col_index" => 64], "db_column" => "payable_amount_miscellaneous_charges"], - ["excel_column" => ["col_name" => "payable_amount_Health_Checkup", "col_index" => 65], "db_column" => "payable_amount_health_checkup"], + ["excel_column" => ["col_name" => "Clinic_DoctorName_Hospital", "col_index" => 56], "db_column" => "Clinic_DoctorName_Hospital"], + ["excel_column" => ["col_name" => "OPD_pincode", "col_index" => 57], "db_column" => "OPD_pincode"], + ["excel_column" => ["col_name" => "payable_amount_OPD_Consultation", "col_index" => 58], "db_column" => "payable_amount_OPD_Consultation"], + ["excel_column" => ["col_name" => "payable_amount_Dental", "col_index" => 59], "db_column" => "payable_amount_Dental"], + ["excel_column" => ["col_name" => "payable_amount_Diagnostics", "col_index" => 60], "db_column" => "payable_amount_Diagnostics"], + ["excel_column" => ["col_name" => "payable_amount_Other", "col_index" => 61], "db_column" => "payable_amount_Other"], + ["excel_column" => ["col_name" => "payable_amount_Pharmacy", "col_index" => 62], "db_column" => "payable_amount_Pharmacy"], + ["excel_column" => ["col_name" => "payable_amount_Vaccination", "col_index" => 63], "db_column" => "payable_amount_Vaccination"], + ["excel_column" => ["col_name" => "payable_amount_Miscellaneous_Charges", "col_index" => 64], "db_column" => "payable_amount_Miscellaneous_Charges"], + ["excel_column" => ["col_name" => "payable_amount_Health_Checkup", "col_index" => 65], "db_column" => "payable_amount_Health_Checkup"], ["excel_column" => ["col_name" => "deduction_amount_copay", "col_index" => 66], "db_column" => "deduction_amount_copay"], ["excel_column" => ["col_name" => "deduction_amount_excess_ailment", "col_index" => 67], "db_column" => "deduction_amount_excess_ailment"], ["excel_column" => ["col_name" => "deduction_amount_excess_policy", "col_index" => 68], "db_column" => "deduction_amount_excess_policy"], @@ -153,6 +153,7 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService // Payment 'utr_no' => 'utr_details', + 'claim_type' => 'tpa_claim_type', ]; protected $statusMapping = [ @@ -166,7 +167,6 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService 'Cashless Document Awaited' => 3, ]; - /** * ABSTRACT FUNCTIONs */ @@ -177,9 +177,8 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_medi_assist'); - $builder->insertBatch($data); + return $builder->insertBatch($data); - return true; } @@ -190,9 +189,7 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService } $ticketMasterModel = new TicketMasterModel(); - $ticketMasterModel->insertBatch($data); - - return true; + return $ticketMasterModel->insertBatch($data); } @@ -216,9 +213,7 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_medi_assist'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -319,7 +314,7 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService if ($isduplicate) { $reason = "This claim already exists in our system."; - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } @@ -338,23 +333,15 @@ class MediAssistClaimImportService extends BaseTpaClaimImportService if (!empty($employee_data)) { $item['emp_id'] = $employee_data['id'] ?? null; $item['emp_name'] = $employee_data['name'] ?? null; + $item['emp_code'] = $employee_data['emp_code'] ?? null; $item['emp_mail'] = $employee_data['email_corporate'] ?? null; $item['emp_mobile'] = $employee_data['mobile'] ?? null; $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; } else { - $reason = sprintf( - 'The policy number "%s" does not exist in our system. ' . - 'Details - Client ID: %s, Client Policy ID: %s, Employee Number: %s, Relationship: %s', - $row['insurer_policy_number'], - $file_data['client_id'], - $file_data['client_policy_id'], - $row['employee_number'], - $item['relationship'] - ); - - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $reason = 'This employee not exist in our system.'; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } diff --git a/app/Libraries/TPAClaimsImportServices/RcareClaimImportService.php b/app/Libraries/TPAClaimsImportServices/RcareClaimImportService.php index 4808d89e..b77b035f 100644 --- a/app/Libraries/TPAClaimsImportServices/RcareClaimImportService.php +++ b/app/Libraries/TPAClaimsImportServices/RcareClaimImportService.php @@ -159,9 +159,7 @@ class RcareClaimImportService extends BaseTpaClaimImportService } $ticketMasterModel = new TicketMasterModel(); - $ticketMasterModel->insertBatch($data); - - return true; + return $ticketMasterModel->insertBatch($data); } @@ -172,9 +170,7 @@ class RcareClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_reliance'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -185,9 +181,7 @@ class RcareClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_reliance'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -291,7 +285,7 @@ class RcareClaimImportService extends BaseTpaClaimImportService if ($isduplicate) { $reason = "This claim already exists in our system."; - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } @@ -310,23 +304,15 @@ class RcareClaimImportService extends BaseTpaClaimImportService if (!empty($employee_data)) { $item['emp_id'] = $employee_data['id'] ?? null; $item['emp_name'] = $employee_data['name'] ?? null; + $item['emp_code'] = $employee_data['emp_code'] ?? null; $item['emp_mail'] = $employee_data['email_corporate'] ?? null; $item['emp_mobile'] = $employee_data['mobile'] ?? null; $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; } else { - $reason = sprintf( - 'The policy number "%s" does not exist in our system. ' . - 'Details - Client ID: %s, Client Policy ID: %s, Employee Number: %s, Relationship: %s', - $row['insurer_policy_number'], - $file_data['client_id'], - $file_data['client_policy_id'], - $row['employee_number'], - $item['relationship'] - ); - - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $reason = 'This employee not exist in our system.'; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } diff --git a/app/Libraries/TPAClaimsImportServices/VidalClaimImportService.php b/app/Libraries/TPAClaimsImportServices/VidalClaimImportService.php index b8bc92b8..fee2cc9f 100644 --- a/app/Libraries/TPAClaimsImportServices/VidalClaimImportService.php +++ b/app/Libraries/TPAClaimsImportServices/VidalClaimImportService.php @@ -163,7 +163,6 @@ class VidalClaimImportService extends BaseTpaClaimImportService ["excel_column" => "Last Document Received date", "db_column" => "last_document_received_date"], ]; - protected $mapping = [ ["excel_column" => ["col_name" => "TPA Policy Number", "col_index" => 0], "db_column" => "tpa_policy_number"], @@ -312,7 +311,6 @@ class VidalClaimImportService extends BaseTpaClaimImportService ["excel_column" => ["col_name" => "Last Document Received date", "col_index" => 113], "db_column" => "last_document_received_date"], ]; - protected $ticketMasterMapping = [ // Policy / Claim identifiers @@ -346,9 +344,9 @@ class VidalClaimImportService extends BaseTpaClaimImportService // Meta 'file_id' => 'file_id', + 'type_of_claim' => 'tpa_claim_type', ]; - protected $statusMapping = [ 'CL Paid with Settlement Letter' => 11, 'CL Rejected' => 8, @@ -380,9 +378,7 @@ class VidalClaimImportService extends BaseTpaClaimImportService } $ticketMasterModel = new TicketMasterModel(); - $ticketMasterModel->insertBatch($data); - - return true; + return $ticketMasterModel->insertBatch($data); } @@ -393,9 +389,7 @@ class VidalClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_vidal'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -406,9 +400,7 @@ class VidalClaimImportService extends BaseTpaClaimImportService } $builder = $this->db->table('claims_dump_vidal'); - $builder->insertBatch($data); - - return true; + return $builder->updateBatch($data, 'id'); } @@ -514,7 +506,7 @@ class VidalClaimImportService extends BaseTpaClaimImportService if ($isduplicate) { $reason = "This claim already exists in our system."; - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } @@ -534,22 +526,14 @@ class VidalClaimImportService extends BaseTpaClaimImportService $item['emp_id'] = $employee_data['id'] ?? null; $item['emp_name'] = $employee_data['name'] ?? null; $item['emp_mail'] = $employee_data['email_corporate'] ?? null; + $item['emp_code'] = $employee_data['emp_code'] ?? null; $item['emp_mobile'] = $employee_data['mobile'] ?? null; $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; } else { - $reason = sprintf( - 'The policy number "%s" does not exist in our system. ' . - 'Details - Client ID: %s, Client Policy ID: %s, Employee Number: %s, Relationship: %s', - $row['insurer_policy_number'], - $file_data['client_id'], - $file_data['client_policy_id'], - $row['employee_number'], - $item['relationship'] - ); - - $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; + $reason = 'This employee not exist in our system.'; + $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } diff --git a/app/Models/ClientDepositModel.php b/app/Models/ClientDepositModel.php index 8a61b204..7aa4ff7b 100755 --- a/app/Models/ClientDepositModel.php +++ b/app/Models/ClientDepositModel.php @@ -30,6 +30,7 @@ class ClientDepositModel extends Model "cd_ac_pk", "record_date", "policy_transaction_id", + "file_id", ]; diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index fa7672ec..6a7c3cac 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -303,6 +303,8 @@ class ClientPolicyModel extends Model $caseSql = ""; } + $url = base_url('employeeRest/downloadCdSplitUpFile?id='); + // Fetch the deposit data based on client and insurer IDs $query = $this->db->table('cash_deposit') ->select('cash_deposit.*') @@ -312,6 +314,12 @@ class ClientPolicyModel extends Model // ->select('policies.name as policy_name') ->select('policy_type.policy_type') ->select('user_profiles.first_name as username') + ->select("CASE + WHEN cash_deposit.file_id IS NOT NULL AND cash_deposit.file_id != '' + THEN CONCAT(" . $this->db->escape($url) . ", cash_deposit.file_id) + ELSE NULL + END AS split_up_url", + false) ->select($caseSql) ->join('user_profiles', 'user_profiles.id = cash_deposit.created_by', 'left') ->join('insurers', 'insurers.id = cash_deposit.insurer_id', 'left') @@ -337,7 +345,9 @@ class ClientPolicyModel extends Model } $query->orderBy('cash_deposit.id', 'DESC'); - return $query->get()->getResult(); + $data = $query->get()->getResult(); + + return $data; } diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index 98243549..74df001c 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -2540,6 +2540,9 @@ pt.ref, pt.data_received_date, + pt.endorse_eff_date, + pt.policy_start_date, + pt.policy_end_date, pt.renewal_date, pt.installment, nhance_branch.branch_name as nhance_branch, @@ -2699,6 +2702,9 @@ pt.ref, pt.data_received_date, + pt.endorse_eff_date, + pt.policy_start_date, + pt.policy_end_date, pt.renewal_date, pt.installment, nhance_branch.branch_name as nhance_branch, @@ -3143,6 +3149,9 @@ pt.ref, pt.data_received_date, + pt.endorse_eff_date, + pt.policy_start_date, + pt.policy_end_date, pt.renewal_date, pt.installment, nhance_branch.branch_name as nhance_branch, @@ -3303,6 +3312,9 @@ pt.ref, pt.data_received_date, + pt.endorse_eff_date, + pt.policy_start_date, + pt.policy_end_date, pt.renewal_date, pt.installment, nhance_branch.branch_name as nhance_branch, @@ -3490,6 +3502,9 @@ pt.ref, pt.data_received_date, + pt.endorse_eff_date, + pt.policy_start_date, + pt.policy_end_date, pt.renewal_date, pt.installment, nhance_branch.branch_name as nhance_branch, @@ -3676,7 +3691,7 @@ $result = $query->getResultArray(); // $countofalldata = count($result); // dd($result); - dd($this->db->getLastQuery()->getQuery()); + // dd($this->db->getLastQuery()->getQuery()); $keys = []; $filtered = []; diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index aa2aa0da..9a461282 100755 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -168,6 +168,7 @@ data-event_type="= $file['event_type'] ?>" data-actions="= $file['actions'] ?>" data-client_branch_id="= $file['client_branch_id'] ?>" + data-issue_date="= $file['policy_issue_date'] ?>" onclick="getBatchFileData(this)" class="dropdown-item upload_button" >Re-Upload @@ -215,6 +216,7 @@ + @@ -329,6 +331,7 @@ let insurer_or_tpa = $(input).data('insurer_or_tpa') let event_type = $(input).data('event_type') let actions = $(input).data('actions') + let issue_date = $(input).data('issue_date') console.log('client_id', client_id); console.log('client_policy_id', client_policy_id); @@ -336,6 +339,7 @@ console.log('insurer_or_tpa', insurer_or_tpa); console.log('event_type', event_type); console.log('actions', actions); + console.log('issue_date', issue_date); $('#batch_file_client_id').val(client_id); $('#batch_file_policy_id').val(client_policy_id); @@ -343,6 +347,7 @@ $('#batch_file_insurer_or_tpa').val(insurer_or_tpa); $('#batch_file_action_type').val(actions); $('#batch_file_event_type').val(event_type); + $('#batch_file_issue_date').val(issue_date); var myModal = new bootstrap.Modal(document.getElementById('batch_file_upload_modal')); diff --git a/app/Views/insurer_basic_info.php b/app/Views/insurer_basic_info.php index aadc43d3..f553b093 100755 --- a/app/Views/insurer_basic_info.php +++ b/app/Views/insurer_basic_info.php @@ -70,7 +70,7 @@ input:checked + .slider:before {