diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d27b33a2..3d8b8f42 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -6,6 +6,9 @@ use CodeIgniter\Router\RouteCollection; /** * @var RouteCollection $routes */ +$routes->post('/chat', 'ChatbotControllerNew::index'); +$routes->get('/widget', 'ChatbotControllerNew::widget'); +$routes->get('/chatbot', 'ChatbotControllerNew::chatbot'); $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']); diff --git a/app/Controllers/Chatbot/BotService.php b/app/Controllers/Chatbot/BotService.php new file mode 100644 index 00000000..ee3b57ad --- /dev/null +++ b/app/Controllers/Chatbot/BotService.php @@ -0,0 +1,110 @@ +reply('Welcome! Please choose an option:', [ + 'reply_markup' => json_encode([ + 'keyboard' => [ + ['Card Download'], + ['Network Hospital'], + ['Reimbursement Claim Process'], + ['Reimbursement Claim Status'], + ['New Policy'], + ['Renew Policy'] + ], + 'resize_keyboard' => true, + 'one_time_keyboard' => true + ]) + ]); + } + + public static function handleCardDownload(BotMan $bot) + { + $bot->reply('Please choose an option:', [ + 'reply_markup' => json_encode([ + 'keyboard' => [ + ['Download Card'], + ['Go Back'] + ], + 'resize_keyboard' => true, + 'one_time_keyboard' => true + ]) + ]); + } + + public static function handleNetworkHospital(BotMan $bot) + { + $bot->reply('Please choose an option:', [ + 'reply_markup' => json_encode([ + 'keyboard' => [ + ['Find Hospital'], + ['Go Back'] + ], + 'resize_keyboard' => true, + 'one_time_keyboard' => true + ]) + ]); + } + + public static function handleReimbursementClaimProcess(BotMan $bot) + { + $bot->reply('Please choose an option:', [ + 'reply_markup' => json_encode([ + 'keyboard' => [ + ['Submit Claim'], + ['Go Back'] + ], + 'resize_keyboard' => true, + 'one_time_keyboard' => true + ]) + ]); + } + + public static function handleReimbursementClaimStatus(BotMan $bot) + { + $bot->reply('Please choose an option:', [ + 'reply_markup' => json_encode([ + 'keyboard' => [ + ['Check Status'], + ['Go Back'] + ], + 'resize_keyboard' => true, + 'one_time_keyboard' => true + ]) + ]); + } + + public static function handleNewPolicy(BotMan $bot) + { + $bot->reply('Please choose an option:', [ + 'reply_markup' => json_encode([ + 'keyboard' => [ + ['Get Quote'], + ['Go Back'] + ], + 'resize_keyboard' => true, + 'one_time_keyboard' => true + ]) + ]); + } + + public static function handleRenewPolicy(BotMan $bot) + { + $bot->reply('Please choose an option:', [ + 'reply_markup' => json_encode([ + 'keyboard' => [ + ['Renew Now'], + ['Go Back'] + ], + 'resize_keyboard' => true, + 'one_time_keyboard' => true + ]) + ]); + } +} \ No newline at end of file diff --git a/app/Controllers/Chatbot/ClaimHandler.php b/app/Controllers/Chatbot/ClaimHandler.php new file mode 100644 index 00000000..b1839734 --- /dev/null +++ b/app/Controllers/Chatbot/ClaimHandler.php @@ -0,0 +1,34 @@ + "Reimbursement Claim Process: Here is a dummy response.", + 'reimbursement_claim_status' => "Reimbursement Claim Status: Here is a dummy response." + ]; + + if (isset($responses[$option])) { + $bot->reply($responses[$option]); + } else { + $bot->reply("Unknown claim option."); + } + + // Send Back Button + self::sendBackButton($bot); + } + + private static function sendBackButton(BotMan $bot) + { + $bot->reply(ButtonTemplate::create("Would you like to return?") + ->addButton(ElementButton::create("Go Back")->type('postback')->payload("main_menu")) + ); + } +} diff --git a/app/Controllers/Chatbot/EcardDownloadConversation.php b/app/Controllers/Chatbot/EcardDownloadConversation.php new file mode 100644 index 00000000..0cc82314 --- /dev/null +++ b/app/Controllers/Chatbot/EcardDownloadConversation.php @@ -0,0 +1,65 @@ +showEcardMenu(); + } + + protected function showEcardMenu() + { + $policy_list = ChatbotHelper::getListOfPolicies(); + $buttons = []; + $question = 'Choose Policy to Download Ecard:'; + if(is_array($policy_list) && count($policy_list)) + { + foreach($policy_list as $policy) + { + // $question = Question::create("Choose Policy to Download Ecard:") + // ->addButtons([ + // Button::create("🔹 $policy['policy_name']")->value("$policy['emp_policy_id']"), + // Button::create("◀️ Go Back")->value("go_back"), + // ]); + $buttons[] = Button::create("🔹 {$policy['policy_name']}")->value($policy['emp_policy_id'].'#'.$policy['rand_string']); + } + } + else + { + $question = 'No policy found'; + } + $buttons = array_merge($buttons,[Button::create("◀️ Go Back")->value("go_back")]); + $question = Question::create($question) + ->addButtons($buttons); + + $this->bot->ask($question, function ($answer) { + // print_r($answer->getValue());die(); + switch ($answer->getValue()) { + case "go_back": + $this->bot->startConversation(new MainMenuConversation()); + break; + case is_string($answer->getValue()) && is_array(explode('#',$answer->getValue())) && count((explode('#',$answer->getValue()))) == 2: + + $link = base_url().'/download-e-card/' . explode('#',$answer->getValue())[1].'/1'; + $this->say('Click here to downlad: Ecard'); + + $this->bot->startConversation(new EcardDownloadConversation()); // ✅ Restart the + + break; + + default: + $this->say("Invalid selection. Please choose an option."); + $this->bot->startConversation(new EcardDownloadConversation()); // ✅ Restart the conversation + break; + } + }); + } +} diff --git a/app/Controllers/Chatbot/MainMenuConversation.php b/app/Controllers/Chatbot/MainMenuConversation.php new file mode 100644 index 00000000..76e150a6 --- /dev/null +++ b/app/Controllers/Chatbot/MainMenuConversation.php @@ -0,0 +1,57 @@ +showMainMenu(); + } + + protected function showMainMenu() + { + $question = Question::create("Please choose") + ->addButtons([ + Button::create("📄 Ecard Download")->value("ecard_download"), + Button::create("🏥 Network Hospital")->value("network_hospital"), + Button::create("💰 Reimbursement Claim Process")->value("reimbursement_claim"), + Button::create("📑 Reimbursement Claim Status")->value("reimbursement_status"), + Button::create("🆕 New Policy")->value("new_policy"), + Button::create("🔄 Renew Policy")->value("renew_policy"), + ]); + + $this->bot->ask($question, function ($answer) { + switch ($answer->getValue()) { + case "ecard_download": + $this->say("📄 Ecard Download Menu:"); + $this->bot->startConversation(new EcardDownloadConversation()); + break; + case "network_hospital": + $this->say("🏥 Network Hospital Menu:"); + $this->bot->startConversation(new NetworkHospitalConversation()); + break; + case "reimbursement_claim": + $this->say("Reimbursement Claim Process selected. (Dummy Response)"); + break; + case "reimbursement_status": + $this->say("Reimbursement Claim Status selected. (Dummy Response)"); + break; + case "new_policy": + $this->say("New Policy selected. (Dummy Response)"); + break; + case "renew_policy": + $this->say("Renew Policy selected. (Dummy Response)"); + break; + default: + $this->say("Invalid selection. Please choose an option."); + $this->bot->startConversation(new MainMenuConversation()); + break; + } + }); + } +} diff --git a/app/Controllers/Chatbot/NetworkHospitalConversation.php b/app/Controllers/Chatbot/NetworkHospitalConversation.php new file mode 100644 index 00000000..70e71340 --- /dev/null +++ b/app/Controllers/Chatbot/NetworkHospitalConversation.php @@ -0,0 +1,44 @@ +showHospitalMenu(); + } + + protected function showHospitalMenu() + { + $question = Question::create("Choose your Network Hospital option:") + ->addButtons([ + Button::create("🔹 Search by City")->value("search_city"), + Button::create("🔹 Search by Pincode")->value("search_pincode"), + Button::create("◀️ Go Back")->value("go_back"), + ]); + + $this->bot->ask($question, function ($answer) { + switch ($answer->getValue()) { + case "search_city": + $this->say("Searching by City... (Dummy Response)"); + break; + case "search_pincode": + $this->say("Searching by Pincode... (Dummy Response)"); + break; + case "go_back": + $this->bot->startConversation(new MainMenuConversation()); + break; + default: + $this->say("Invalid selection. Please choose an option."); + $this->showHospitalMenu(); + break; + } + }); + } +} diff --git a/app/Controllers/Chatbot/PolicyHandler.php b/app/Controllers/Chatbot/PolicyHandler.php new file mode 100644 index 00000000..9491ef9d --- /dev/null +++ b/app/Controllers/Chatbot/PolicyHandler.php @@ -0,0 +1,36 @@ + "Ecard Download: Here is a dummy response.", + 'network_hospital' => "Network Hospital: Here is a dummy response.", + 'new_policy' => "New Policy: Here is a dummy response.", + 'renew_policy' => "Renew Policy: Here is a dummy response." + ]; + + if (isset($responses[$option])) { + $bot->reply($responses[$option]); + } else { + $bot->reply("Unknown policy option."); + } + + // Send Back Button + self::sendBackButton($bot); + } + + private static function sendBackButton(BotMan $bot) + { + $bot->reply(ButtonTemplate::create("Would you like to return?") + ->addButton(ElementButton::create("Go Back")->type('postback')->payload("main_menu")) + ); + } +} diff --git a/app/Controllers/ChatbotControllerNew.php b/app/Controllers/ChatbotControllerNew.php new file mode 100644 index 00000000..fc6bd75a --- /dev/null +++ b/app/Controllers/ChatbotControllerNew.php @@ -0,0 +1,90 @@ +myLogger = \Config\Services::mylogger(); + $this->session = \Config\Services::session(); + + $this->myLogger->logme('error', 'CALLED'); + + // Load BotMan driver + DriverManager::loadDriver(WebDriver::class); + + // Setup BotMan with cache + $cache = new SymfonyCache(new FilesystemAdapter()); + $this->botman = BotManFactory::create([], $cache); + + // Retrieve user ID from session or request + $extras = request()->getGet('conf'); + $extras = json_decode($extras); + $router = service('router'); + $method = $router->methodName(); + $this->myLogger->logme('error', $method); + + if (isset($extras) && $method == 'widget') { + $extras = $extras->parameters; + $this->session->set('CHATBOT_USER_ID', $extras->employee_id); + } + + $this->myLogger->logme('error', $this->session->get('CHATBOT_USER_ID')); + + // print_rr(ChatbotHelper::getListOfPolicies());die(); + } + + public function index() + { + // Start the Main Menu when user says "hi" or "start" + $this->botman->hears('start|hi|hello', function (BotMan $bot) { + $bot->reply('How how can i assit?'); + $bot->startConversation(new MainMenuConversation()); + }); + + // $this->botman->hears('main_menu', function (BotMan $bot) { + // BotService::sendMainOptions($bot); + // }); + + // // Register Option Handlers + // $this->registerHandlers(); + + // Listen for Messages + $this->botman->listen(); + } + + private function registerHandlers() + { + // Handling Policy and Claims + $this->botman->hears('group:policy:{option}', [\App\Controllers\Chatbot\PolicyHandler::class, 'handle']); + $this->botman->hears('group:claim:{option}', [\App\Libraries\Chatbot\ClaimHandler::class, 'handle']); + + + } + + public function chatbot() + { + $this->loadLayout('chatbot.php'); + } + + public function widget() + { + echo view('widget.php'); + } +} diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index da83ee07..9cf89d53 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1658,7 +1658,7 @@ class MasterController extends AdminController $email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id; $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]); echo "Inside the master controller"; - print_r($res['data']['zepto_api']); + print_r($res); } diff --git a/app/Helpers/ChatbotHelper.php b/app/Helpers/ChatbotHelper.php new file mode 100644 index 00000000..0b547cd0 --- /dev/null +++ b/app/Helpers/ChatbotHelper.php @@ -0,0 +1,28 @@ +getEmpFamilybyEmpCode(emp_code: $emp_code,client_id: $client_id,emp_status: ['draft'],policy_status:['draft'],client_branch_id:[ $client_branch_id ],relationship:[$relationship]); + } + + +} + +?> diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index ca22481a..2e932ab7 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -235,7 +235,7 @@ if (!function_exists('get_username')) { if (!function_exists('get_role_id')) { function get_role_id() { - $role_id = get_session_userdata()->role; + $role_id = isset(get_session_userdata()->role) ? get_session_userdata()->role : null; return $role_id; } } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 22b37956..d8fd4894 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -106,7 +106,7 @@ class EmployeeModel extends Model public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [],array $client_branch_id = []) { - $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employees.file_id','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policy_type.long_name as policy_name','client_policy.is_addon', 'employee_polices.payable_employee']) + $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employees.file_id','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policy_type.long_name as policy_name','client_policy.is_addon', 'employee_polices.payable_employee','employee_polices.rand_string','employee_polices.claim_status']) ->join('employee_polices', 'employee_polices.employee_id = employees.id') ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id','left') diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 24b360d4..cd60ad34 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -1732,7 +1732,7 @@ class EmployeePolicyModel extends Model employee_polices ep WHERE ep.file_id = $file_id - AND ep.uhid IS NOT NULL' + AND ep.uhid IS NOT NULL AND ep.status != 'truncated' AND ep.status != 'truncated' AND ep.is_active = 1; diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index 197a5b66..246609cd 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -494,7 +494,7 @@ class PolicyTransactionModel extends Model ") ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left') - ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left') + // ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left') ->join('clients', 'clients.id = policy_transaction.client_id') ->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left') ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') @@ -519,19 +519,27 @@ class PolicyTransactionModel extends Model $builder->where('policy_transaction.'.$date_type.'>=', $startDate) ->where('policy_transaction.'.$date_type.'<=', $endDate); - }else{ - - // $fromDate = date('Y-m-d', strtotime('-30 days')); - // $toDate = date('Y-m-d 23:59:59'); - - // $builder->where('policy_transaction.created_at >=', $fromDate) - // ->where('policy_transaction.created_at <=', $toDate); } - if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0){ + // if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0){ - $builder->where('policy_transaction.month >=', $startDate) - ->where('policy_transaction.month <=', $endDate); + // $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); + // $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); + // $builder->where('policy_transaction.month >=', $startDate) + // ->where('policy_transaction.month <=', $endDate); + // } + + // Conditionally join insurer_statements if $date_type == 'statement_month' + if ($date_type == 'statement_month' && $start_date != 0 && $end_date != 0) { + $startDate = date('Y-m-d', strtotime($start_date)); + $endDate = date('Y-m-d', strtotime($end_date)); + + $builder->join('co_share_stmt_details', 'pt_co_share_details.id = co_share_stmt_details.co_share_id', 'left') + ->join('insurer_statements', 'co_share_stmt_details.statement_id = insurer_statements.id','left') + ->where('insurer_statements.is_active', 1) + ->where('insurer_statements.month >=', $startDate) + ->where('insurer_statements.month <=', $endDate) + ->groupBy('co_share_stmt_details.co_share_id'); } if ($client_id != 0) { diff --git a/app/Views/chatbot.php b/app/Views/chatbot.php new file mode 100644 index 00000000..77adf697 --- /dev/null +++ b/app/Views/chatbot.php @@ -0,0 +1,83 @@ + + + + + + Insurance ChatBot + + + + +

Welcome to Insurance ChatBot

+ + + + + + + + + + diff --git a/app/Views/report_bds.php b/app/Views/report_bds.php index 44d06bd6..815eecb5 100644 --- a/app/Views/report_bds.php +++ b/app/Views/report_bds.php @@ -230,7 +230,7 @@ $(document).ready(function() { paging: true, // Enable pagination pageLength: 25, // Set default number of rows per page (optional) ordering: false, - "footerCallback": function(row, data, start, end, display) { + "footerCallback": function(row, data, start, end, display) { var api = this.api(); // Calculate column totals @@ -238,9 +238,11 @@ $(document).ready(function() { return parseFloat(a) + parseFloat(b) || 0; }, 0); - var total_rewards = api.column(26).data().reduce(function(a,b){ + var total_rewards = api.column(26).data().reduce(function(a, b) { return parseFloat(a) + parseFloat(b) || 0; - }) + }, 0); // Add initial value 0 here + + console.log('total_rewards - ' + total_rewards); var totalIrda = api.column(27).data().reduce(function(a, b) { return parseFloat(a) + parseFloat(b) || 0; @@ -256,7 +258,7 @@ $(document).ready(function() { // Update the totals in the div above the table $('#total_premium').text(totalPremium.toFixed(2)); - $('#total_rewards').text(total_rewards.toFixed(2)) + $('#total_rewards').text(total_rewards.toFixed(2)); $('#total_irda').text(totalIrda.toFixed(2)); $('#total_billed').text(totalBilled.toFixed(2)); $('#total_unbilled').text(totalUnbilled.toFixed(2)); diff --git a/app/Views/widget.php b/app/Views/widget.php new file mode 100644 index 00000000..1b14b195 --- /dev/null +++ b/app/Views/widget.php @@ -0,0 +1,15 @@ + + + + BotMan Widget + + + + + + + + + + + \ No newline at end of file diff --git a/composer.json b/composer.json index c456241c..467fb3a4 100755 --- a/composer.json +++ b/composer.json @@ -14,6 +14,8 @@ "ext-intl": "*", "ext-json": "*", "ext-mbstring": "*", + "botman/botman": "^2.8", + "botman/driver-web": "^1.5", "dompdf/dompdf": "^2.0", "firebase/php-jwt": "^6.10", "google/apiclient": "^2.15.0", @@ -25,6 +27,7 @@ "psr/http-message": "^1.0", "psr/log": "^1.1", "slim/slim": "^4.13", + "symfony/cache": "^7.2", "zircote/swagger-php": "^4.8" }, "require-dev": {