From 8f811a780a5e07181a88752c4e0c528f0a07e16e Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Tue, 21 Jul 2026 12:14:43 +0530 Subject: [PATCH] CHANGE_MEMEBR_SUMMERY_SHOW_TYPE_2_HANDLE_IN_MAIL --- app/Commands/TestMemberReviewSummaryMail.php | 487 +++++++ app/Helpers/sendMailNotification.php | 1288 +++++++++++++++++- 2 files changed, 1766 insertions(+), 9 deletions(-) create mode 100644 app/Commands/TestMemberReviewSummaryMail.php diff --git a/app/Commands/TestMemberReviewSummaryMail.php b/app/Commands/TestMemberReviewSummaryMail.php new file mode 100644 index 0000000..88b61c2 --- /dev/null +++ b/app/Commands/TestMemberReviewSummaryMail.php @@ -0,0 +1,487 @@ + 'Recipient email address (required)', + '--premium-summary' => 'is_premium_summery value: 0=hide, 1=full columns, 2=Policy Name/Total only (default: 2)', + '--type' => 'Sample data type: full|topup|parents|base|payable|simple (default: full)', + '--client-id' => 'Client ID (optional; auto-picks a client with enabled template)', + '--dry-run' => 'Build mail and save HTML under writable/tmp; do not send', + ]; + + public function run(array $params) + { + $mail = $this->optionValue('mail', $params[0] ?? null); + if (empty($mail) || ! filter_var($mail, FILTER_VALIDATE_EMAIL)) { + CLI::error('Provide a valid --mail you@example.com'); + CLI::write($this->usage, 'yellow'); + + return; + } + + $premiumSummary = (int) ($this->optionValue('premium-summary', 2)); + if (! in_array($premiumSummary, [0, 1, 2], true)) { + CLI::error('--premium-summary must be 0, 1, or 2'); + + return; + } + + $type = strtolower((string) ($this->optionValue('type', 'full'))); + if (! in_array($type, ['full', 'topup', 'parents', 'base', 'payable', 'simple'], true)) { + CLI::error('--type must be one of: full, topup, parents, base, payable, simple'); + + return; + } + + $clientId = $this->optionValue('client-id'); + $dryRun = CLI::getOption('dry-run') !== null || $this->hasFlag('dry-run'); + + $clientModel = new ClientModel(); + $clientPolicyModel = new ClientPolicyModel(); + $notificationModel = new NotificationModel(); + + $client = $this->resolveClient($clientModel, $notificationModel, $clientId); + if ($client === null) { + return; + } + + $notification = $notificationModel + ->where('client_id', $client['id']) + ->where('template_name', 'member_review_and_summary_mail') + ->first(); + + if (empty($notification)) { + CLI::error("No member_review_and_summary_mail template for client #{$client['id']}"); + + return; + } + + $wasEnabled = (int) ($notification['enabled'] ?? 0); + if ($wasEnabled !== 1) { + CLI::write('Template is disabled; temporarily enabling for this test...', 'yellow'); + $notificationModel->update($notification['id'], ['enabled' => 1]); + $notification['enabled'] = 1; + } + + $policies = $this->resolvePolicies($clientPolicyModel, (int) $client['id'], $type); + if ($policies === null) { + if ($wasEnabled !== 1) { + $notificationModel->update($notification['id'], ['enabled' => $wasEnabled]); + } + + return; + } + + $originalPremiumSummary = []; + foreach ($policies as $key => $policy) { + $originalPremiumSummary[$policy['id']] = $policy['is_premium_summery'] ?? 0; + $clientPolicyModel->update($policy['id'], ['is_premium_summery' => $premiumSummary]); + $policies[$key]['is_premium_summery'] = $premiumSummary; + } + + try { + $arrayList = $this->buildSampleArrayList($type, $policies, $mail); + + CLI::write('Test config:', 'yellow'); + CLI::write(" client_id : {$client['id']} ({$client['client_name']})"); + CLI::write(" recipient : {$mail}"); + CLI::write(" premium-summary : {$premiumSummary} " . $this->premiumSummaryLabel($premiumSummary)); + CLI::write(" sample type : {$type}"); + CLI::write(' policy group(s) : ' . count($arrayList)); + foreach ($policies as $label => $policy) { + CLI::write(" [{$label}] id={$policy['id']} type={$policy['policy_type_id']} is_addon={$policy['is_addon']}"); + } + + $paramsMail = [ + 'array_list' => $arrayList, + 'client_policy_id' => array_column($policies, 'id'), + 'emp_code' => 'TEST001', + 'client_id' => $client['id'], + 'notification' => $notification, + 'common' => [ + 'client_id' => $client['id'], + 'client_branch_id' => null, + 'client_policy_id' => null, + 'employee_policy_id' => null, + 'employee_id' => null, + 'mail_type' => 'member_review_and_summary_mail', + ], + ]; + + $wholeData = sendMailNotification::sendMailNotification('member_review_and_summary_mail', $paramsMail); + + if (empty($wholeData[0]['message'] ?? null)) { + CLI::error('Mail payload was empty. Check that the notification template is enabled and sample data is valid.'); + + return; + } + + // Force recipient to the provided test mail + $wholeData[0]['mail'] = $mail; + $wholeData[0]['bcc'] = ''; + + $htmlPath = WRITEPATH . 'tmp/member_review_summary_' . $premiumSummary . '_' . $type . '_' . date('Ymd_His') . '.html'; + if (! is_dir(WRITEPATH . 'tmp')) { + mkdir(WRITEPATH . 'tmp', 0775, true); + } + file_put_contents($htmlPath, $wholeData[0]['message']); + CLI::write("Saved preview HTML: {$htmlPath}", 'green'); + + if ($dryRun) { + CLI::write('Dry-run only — email was not sent.', 'yellow'); + CLI::write('Subject: ' . ($wholeData[0]['subject'] ?? ''), 'white'); + + return; + } + + $result = MailHelper::send_email($wholeData[0]); + CLI::write('Send result:', 'yellow'); + CLI::write(is_string($result) ? $result : json_encode($result)); + CLI::write("Mail sent to {$mail}", 'green'); + } finally { + foreach ($originalPremiumSummary as $policyId => $originalValue) { + $clientPolicyModel->update($policyId, ['is_premium_summery' => $originalValue]); + } + if ($wasEnabled !== 1) { + $notificationModel->update($notification['id'], ['enabled' => $wasEnabled]); + } + CLI::write('Restored original is_premium_summery / notification enabled flags.', 'white'); + } + } + + private function premiumSummaryLabel(int $value): string + { + return match ($value) { + 0 => '(hide premium summary)', + 1 => '(full Premium/GST columns + summary)', + 2 => '(hide columns; summary Policy Name/Total only)', + default => '', + }; + } + + private function resolveClient(ClientModel $clientModel, NotificationModel $notificationModel, $clientId): ?array + { + if (! empty($clientId)) { + $client = $clientModel->where('id', (int) $clientId)->where('is_active', 1)->first(); + if (empty($client)) { + CLI::error("Client #{$clientId} not found or inactive"); + + return null; + } + + return $client; + } + + $notification = $notificationModel + ->where('template_name', 'member_review_and_summary_mail') + ->where('enabled', 1) + ->where('client_id >', 0) + ->orderBy('id', 'DESC') + ->first(); + + if (empty($notification['client_id'])) { + // Fallback: any template row with client_id + $notification = $notificationModel + ->where('template_name', 'member_review_and_summary_mail') + ->where('client_id >', 0) + ->orderBy('id', 'DESC') + ->first(); + } + + if (empty($notification['client_id'])) { + CLI::error('No client found with member_review_and_summary_mail template. Pass --client-id=ID'); + + return null; + } + + $client = $clientModel->where('id', $notification['client_id'])->where('is_active', 1)->first(); + if (empty($client)) { + CLI::error('Resolved client is missing/inactive. Pass --client-id=ID'); + + return null; + } + + return $client; + } + + /** + * @return array|null + */ + private function resolvePolicies(ClientPolicyModel $clientPolicyModel, int $clientId, string $type): ?array + { + $policies = $clientPolicyModel + ->where('client_id', $clientId) + ->where('is_active', 1) + ->findAll() ?? []; + + if (empty($policies)) { + CLI::error("No active client_policy rows for client #{$clientId}"); + + return null; + } + + $withPremium = []; + foreach ($policies as $policy) { + if ($this->hasPremiumConfig($policy)) { + $withPremium[] = $policy; + } + } + + if (empty($withPremium)) { + CLI::error("No client_policy with active premium config for client #{$clientId}"); + + return null; + } + + $pick = static function (array $list, ?callable $pref = null) { + if ($pref !== null) { + foreach ($list as $row) { + if ($pref($row)) { + return $row; + } + } + } + + return $list[0]; + }; + + $result = []; + + if (in_array($type, ['full', 'base', 'topup', 'parents', 'simple'], true)) { + $result['main'] = $pick($withPremium, static function ($p) { + return in_array((int) ($p['is_addon'] ?? 0), [2, 3], true) + || in_array((int) ($p['policy_type_id'] ?? 0), [1, 2, 3, 6, 7], true); + }); + } + + if (in_array($type, ['full', 'payable'], true)) { + $payable = $pick($withPremium, static function ($p) { + return (int) ($p['policy_type_id'] ?? 0) === 2; + }); + if ((int) ($payable['policy_type_id'] ?? 0) !== 2) { + CLI::write('Warning: no policy_type_id=2 found; payable sample will use main policy and may skip payable table.', 'yellow'); + } + $result['payable'] = $payable; + } + + if ($type === 'payable' && empty($result['payable'])) { + CLI::error('Could not resolve a policy for payable sample type'); + + return null; + } + + if ($type !== 'payable' && empty($result['main'])) { + CLI::error('Could not resolve a policy for sample type'); + + return null; + } + + // Deduplicate by id while keeping labels + $unique = []; + foreach ($result as $label => $policy) { + $unique[$label] = $policy; + } + + return $unique; + } + + private function hasPremiumConfig(array $policy): bool + { + $policyId = (int) $policy['id']; + $typeId = (int) ($policy['policy_type_id'] ?? 0); + + if (in_array($typeId, [1, 6, 7], true)) { + $row = (new PolicyPremium1Model()) + ->where('client_policy_id', $policyId) + ->where('is_active', '1') + ->first(); + } else { + $row = (new PolicyPremium2Model()) + ->where('client_policy_id', $policyId) + ->where('is_active', '1') + ->first(); + } + + return ! empty($row); + } + + /** + * Build array_list shaped like getEmpFamilybyEmpCode() groups. + * + * @param array $policies + */ + private function buildSampleArrayList(string $type, array $policies, string $mail): array + { + $list = []; + + if (isset($policies['main']) && in_array($type, ['full', 'base'], true)) { + $p = $policies['main']; + $list[] = [ + $this->memberRow($p, 'Self', 'Ravi Kumar', $mail, 500000, 0, 0, 1, 0), + $this->memberRow($p, 'Spouse', 'Anita Kumar', '', 0, 0, 0, 1, 0), + $this->memberRow($p, 'Child', 'Arjun Kumar', '', 0, 0, 0, 1, 0), + ]; + } + + // Single-policy layout matching UI mock: Health Insurance Plan + Premium/GST + summary + if (isset($policies['main']) && $type === 'simple') { + $p = $policies['main']; + $list[] = [ + $this->memberRow( + $p, + 'Self', + 'John Doe', + $mail, + 500000, + 12000, + 2160, + 2, + 0, + 'Health Insurance Plan', + 'E12345' + ), + ]; + } + + if (isset($policies['main']) && in_array($type, ['full', 'topup'], true)) { + $p = $policies['main']; + $list[] = [ + $this->memberRow($p, 'Self', 'Ravi Kumar', $mail, 300000, 4500, 810, 2, 0, 'SI Top-up Cover'), + $this->memberRow($p, 'Spouse', 'Anita Kumar', '', 300000, 3200, 576, 2, 0, 'SI Top-up Cover'), + ]; + } + + if (isset($policies['main']) && in_array($type, ['full', 'parents'], true)) { + $p = $policies['main']; + $list[] = [ + $this->memberRow($p, 'Self', 'Ravi Kumar', $mail, 200000, 0, 0, 3, 0, 'Parent Medical Cover'), + $this->memberRow($p, 'Father', 'Suresh Kumar', '', 200000, 6000, 1080, 3, 0, 'Parent Medical Cover'), + $this->memberRow($p, 'Mother', 'Lakshmi Kumar', '', 200000, 5500, 990, 3, 0, 'Parent Medical Cover'), + ]; + } + + if (isset($policies['payable']) && in_array($type, ['full', 'payable'], true)) { + $p = $policies['payable']; + $list[] = [ + $this->memberRow($p, 'Self', 'Ravi Kumar', $mail, 400000, 2800, 504, 1, 1, 'Voluntary Top-up'), + $this->memberRow($p, 'Spouse', 'Anita Kumar', '', 400000, 2100, 378, 1, 1, 'Voluntary Top-up'), + ]; + } + + return $list; + } + + private function memberRow( + array $policy, + string $relationship, + string $name, + string $email, + float $si, + float $premium, + float $gst, + int $isAddon, + int $payableEmployee, + ?string $policyName = null, + string $empCode = 'TEST001' + ): array { + $dobOffsets = [ + 'Self' => '-38 years', + 'Spouse' => '-35 years', + 'Child' => '-10 years', + 'Father' => '-65 years', + 'Mother' => '-62 years', + ]; + + // Match mock DOB for simple Health Insurance Plan sample + $dob = ($name === 'John Doe' && $empCode === 'E12345') + ? '1985-05-15' + : date('Y-m-d', strtotime($dobOffsets[$relationship] ?? '-30 years')); + + return [ + 'emp_id' => 90001, + 'client_id' => $policy['client_id'], + 'client_branch_id' => null, + 'relationship' => $relationship, + 'emp_code' => $empCode, + 'name' => $name, + 'email_corporate' => $email, + 'mobile' => '9876543210', + 'dob' => $dob, + 'client_policy_id' => $policy['id'], + 'basic_cover_si' => $si, + 'premium' => $premium, + 'rata_premimum' => $premium, + 'gst' => $gst, + 'policy_name' => $policyName ?? ('Sample Policy #' . $policy['id']), + 'is_addon' => $isAddon, + 'payable_employee' => $payableEmployee, + ]; + } + + /** + * Read CLI option from CI helper or raw argv (--key=value / --key value). + */ + private function optionValue(string $name, $default = null) + { + $fromCli = CLI::getOption($name); + if ($fromCli !== null && $fromCli !== false && $fromCli !== '') { + return $fromCli; + } + + $argv = $_SERVER['argv'] ?? []; + foreach ($argv as $i => $arg) { + if ($arg === '--' . $name && isset($argv[$i + 1]) && strpos((string) $argv[$i + 1], '-') !== 0) { + return $argv[$i + 1]; + } + if (strpos((string) $arg, '--' . $name . '=') === 0) { + return substr((string) $arg, strlen($name) + 3); + } + } + + return $default; + } + + private function hasFlag(string $name): bool + { + if (CLI::getOption($name) !== null) { + return true; + } + + $argv = $_SERVER['argv'] ?? []; + foreach ($argv as $arg) { + if ($arg === '--' . $name || strpos((string) $arg, '--' . $name . '=') === 0) { + return true; + } + } + + return false; + } +} diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 21f2097..3995639 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -196,6 +196,1256 @@ class sendMailNotification + $mail_content = preg_replace('/]*>( |\s)*<\/p>/i', '', $mail_content); + + $data['params'] = $params;$data['client_logo'] = $client_logo; + $data['mail_content'] = $mail_content; + $mail_content = view('mail_template', $data); + + + $wholeData = ['mail' => $mail, 'subject' => $subject, 'message' => $mail_content, 'bcc' => $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; + + return $wholeData; + } else if ($action == 'member_review_and_summary_mail') { + + $array_list = $params['array_list']; //employeee lst + $client_policy_id = $params['client_policy_id']; + $emp_code = $params['emp_code']; + $client_id = $params['client_id']; + $common = $params['common']; + + $clientModel = new ClientModel(); + $notificationModel = new NotificationModel(); + $clientPolicyModel = new ClientPolicyModel(); + $PolicyPremium1Model = new PolicyPremium1Model(); + $PolicyPremium2Model = new PolicyPremium2Model(); + + + $client_data = $clientModel->where('id', $client_id)->first(); + $notification_data = $notificationModel->where('client_id', $client_id)->where('template_name', $action)->first(); + + $params['client_data'] = $client_data; + // dd($notification_data); + + if (isset($notification_data) && $notification_data['enabled'] == 1) { + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + // $client_logo = $nhance_logo; + + $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content); + $mail_content = str_replace(["[[nhance_logo]]", "{{nhance_logo}}"], "Nhance Logo", $mail_content); + $mail_content = str_replace(["[[client_logo]]", "{{client_logo}}"], "Client Logo", $mail_content); + + $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content); + + // Step 1: Replace the placeholder with an HTML table structure + $mail = ''; + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $Addon_list = []; + $name = ''; + $employee_mobile_no = ''; + $emp_code = ''; + // is_premium_summery: 0=hide all, 1=full premium/GST + summary, 2=hide columns but summary as Policy Name/Total + $show_full_premium_breakdown = false; + + // echo '
';
+                // dd($array_list); die;
+
+
+
+                foreach ($array_list as $item) {
+
+                    $payable_employee_array = [];
+
+                    if (count($item) != 0) {
+
+                        $table_content .= '

Policy Type :'; + $temp_data = ''; + $policy_name = ''; + $is_addon = ''; + $rowspan = count($item) ?? 2; + $is_si_set = 0; + + foreach ($item as $inner_item) { + + //getting policy premium data + $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + if ($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7) { + $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } else { + $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } + //end of getting policy premium data + + // dd($policy_premium_data); + + if ($inner_item['payable_employee'] == 1 && $client_policy_data['policy_type_id'] == 2) { + $payable_employee_array['emp_data'][] = $inner_item; + } + + // dd($policy_premium_data); + + $policy_name = $inner_item['policy_name']; + + if ($inner_item['relationship'] == 'Self') { + // $emp_code = '(' . $inner_item['emp_code'] . ')'; + $emp_code = ' ( Employee Code : ' . $inner_item['emp_code'] . ')'; + $mail = $inner_item['email_corporate']; + $name = $inner_item['name']; + $employee_mobile_no = $inner_item['mobile']; + } + + $si = ''; + $premium = ''; + $gst_forself = ''; + $is_premium_summery = (int) ($client_policy_data['is_premium_summery'] ?? 0); + $show_premium_columns = ($is_premium_summery === 1); + + if ($policy_premium_data['premium_type'] == 2) { + $si = '₹ ' . format_indian_number($inner_item['basic_cover_si']); + } else { + if ($inner_item['relationship'] == 'Self') { + $payable_employee_array['si_amount'] = $inner_item['basic_cover_si']; + $payable_employee_array['self_premium'] = $inner_item['rata_premimum']; + $payable_employee_array['self_gst'] = $inner_item['gst']; + } + empty($inner_item['basic_cover_si']) ? $si = 0 : $si = '₹ ' . format_indian_number($inner_item['basic_cover_si']); + } + + // Premium summery for show and hide the Additional premium data + if ($show_premium_columns) { + $premium = '₹ ' . format_indian_number(round($inner_item['rata_premimum'])); + $gst_forself = '₹ ' . format_indian_number(round($inner_item['gst'])); + } + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + + if ($policy_premium_data['premium_type'] == 2) { + $temp_data .= '' . $si . ''; + } else { + // $temp_data .= (($si != 0 && count($item) != 1) ? ('' . $si . '') : ($si == 0 ? "" : '' . $si . '') ); + + if ($si != 0 && count($item) != 1 && $is_si_set == 0) { + + $temp_data .= '' . $si . ''; + $is_si_set = 1; + } else { + + if ($is_si_set == 1) { + $temp_data .= ''; + } else { + $temp_data .= '' . $si . ''; + } + } + } + + // Only Display SI Topup and Dependent Addon + if (($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) && $show_premium_columns) { + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + } + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + } + + $policy_name_for_policy_type = $inner_item['policy_name']; + if ($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3) { + $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + } + + $is_premium_summery = (int) ($client_policy_data['is_premium_summery'] ?? 0); + $show_premium_columns = ($is_premium_summery === 1); + $include_addon_summary = in_array($is_premium_summery, [1, 2], true); + + $table_content .= $policy_name_for_policy_type . '

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if (($is_addon == 2 || $is_addon == 3) && $show_premium_columns) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + if (($is_addon == 2 || $is_addon == 3) && $include_addon_summary) { + if ($show_premium_columns) { + $show_full_premium_breakdown = true; + } + $addon_list_array = [ + 'policy_name' => $policy_name_for_policy_type, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + } + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; + } + + // Kint::dump($payable_employee_array); + // dd(count($payable_employee_array['emp_data'])); + + if (isset($payable_employee_array['emp_data']) && count($payable_employee_array['emp_data']) > 0) { + + $table_content .= '

Policy Type :'; + $temp_data = ''; + $is_addon = ''; + $rowspan = count($payable_employee_array['emp_data']) ?? 2; + + $self_si_amount = $payable_employee_array['si_amount'] ?? 0; + $self_premium = $payable_employee_array['self_premium'] ?? 0; + $self_gst = $payable_employee_array['self_gst'] ?? 0; + + + // dd($payable_employee_array['si_amount'], $self_si_amount); + + foreach ($payable_employee_array['emp_data'] as $inner_item) { + + //getting policy premium data + $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + if ($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7) { + $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } else { + $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } + //end of getting policy premium data + + // dd($policy_premium_data); + + $si = ''; + $premium = ''; + $gst_forself = ''; + $is_premium_summery = (int) ($client_policy_data['is_premium_summery'] ?? 0); + // value 2: hide Premium/GST columns even for payable-by-employee rows + $show_premium_columns = ($is_premium_summery === 1) + || ($inner_item['payable_employee'] == 1 && $is_premium_summery !== 2); + + if ($policy_premium_data['premium_type'] == 2) { + $si = '₹ ' . format_indian_number($inner_item['basic_cover_si']); + } else { + empty($self_si_amount) ? $si = 0 : $si = '₹ ' . format_indian_number($self_si_amount); + } + + if ($policy_premium_data['premium_type'] == 1) { + + empty($self_premium) ? $premium = 0 : $premium = '₹ ' . format_indian_number($self_premium); + empty($self_gst) ? $gst_forself = 0 : $gst_forself = '₹ ' . format_indian_number($self_gst); + } else { + + $premium = '₹ ' . format_indian_number(round($inner_item['rata_premimum'])); + $gst_forself = '₹ ' . format_indian_number(round($inner_item['gst'])); + } + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + + // dd($si); + + // Premium summery for show and hide the Additional premium data + if ($show_premium_columns) { + if ($policy_premium_data['premium_type'] == 2) { + + $temp_data .= '' . $si . ''; + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + } else { + + if ($policy_premium_data['premium_type'] == 1) { + + $temp_data .= (($si != 0 && count($item) != 1) ? ('' . $si . '') : ($si == 0 ? "" : '' . $si . '')); + $temp_data .= (($premium != 0 && count($item) != 1) ? ('' . $premium . '') : ($premium == 0 ? "" : '' . $premium . '')); + $temp_data .= (($gst_forself != 0 && count($item) != 1) ? ('' . $gst_forself . '') : ($gst_forself == 0 ? "" : '' . $gst_forself . '')); + } else { + + $temp_data .= (($si != 0 && count($item) != 1) ? ('' . $si . '') : ($si == 0 ? "" : '' . $si . '')); + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + } + + $self_si_amount = 0; + $self_premium = 0; + $self_gst = 0; + } + } else { + $temp_data .= '' . $si . ''; + } + + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + + $policy_name_for_policy_type = $inner_item['policy_name']; + if ($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3) { + $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + } + + $is_premium_summery = (int) ($client_policy_data['is_premium_summery'] ?? 0); + $show_premium_columns = ($is_premium_summery === 1) + || ($inner_item['payable_employee'] == 1 && $is_premium_summery !== 2); + $include_addon_summary = ($inner_item['payable_employee'] == 1) + || in_array($is_premium_summery, [1, 2], true); + + $table_content .= $policy_name_for_policy_type . ' ( Payable By Employee )

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Premium summery for show and hide the Additional premium data + if ($show_premium_columns) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + // Premium summery for show and hide the Additional premium data + if ($include_addon_summary) { + if ($is_premium_summery !== 2) { + $show_full_premium_breakdown = true; + } + $addon_list_array = [ + 'policy_name' => $policy_name_for_policy_type . '( Payable By Employee )', + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + } + + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; + } + } + + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= ''; + + // Center align for table header and body + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + if ($show_full_premium_breakdown) { + $table_content .= ''; + $table_content .= ''; + } + // is_premium_summery == 2: label as Total Premium + $total_label = $show_full_premium_breakdown ? 'Total' : 'Total Premium'; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $sum_total = 0; + foreach ($Addon_list as $key => $value) { + $total_addon = $value['gst'] + $value['addtional_premium']; + $sum_total += $total_addon; + + $table_content .= ''; + $table_content .= ''; + if ($show_full_premium_breakdown) { + $table_content .= ''; + $table_content .= ''; + } + $table_content .= ''; + $table_content .= ''; + } + + $sum_total_words = numberToWords($sum_total); + $table_content .= ''; + if ($show_full_premium_breakdown) { + $table_content .= ''; + } else { + $table_content .= ''; + } + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGST' . $total_label . '
' . $value['policy_name'] . '₹' . format_indian_number($value['addtional_premium']) . '₹' . format_indian_number($value['gst']) . '₹' . format_indian_number($total_addon) . '
Total' . $total_label . '₹' . format_indian_number($sum_total) . '
'; + // $table_content .= '
' . $sum_total_words . '
'; + } + + // dd($payable_employee_array, $Addon_list); + // print_r($table_content); die; + + $mail_content = str_replace(["[[member_name]]", "{{member_name}}"], $name . $emp_code, $mail_content); + $mail_content = str_replace(["[[member_mobile]]", "{{member_mobile}}"], $employee_mobile_no, $mail_content); + $mail_content = str_replace(["[[member_summary]]", "{{member_summary}}"], $table_content, $mail_content); + + + $mail_content = preg_replace('/]*>( |\s)*<\/p>/i', '', $mail_content); + + $data['params'] = $params;$data['client_logo'] = $client_logo; + $data['mail_content'] = $mail_content; + $mail_content = view('mail_template', $data); + + + $wholeData[] = ['mail' => $mail, 'subject' => $subject, 'message' => $mail_content, 'bcc' => $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; + + return $wholeData; + } + } else if ($action == 'account_maneger_summary_mail') { + + $client_id = $params['client_id']; + $client_policy_id = $params['client_policy_id']; + $common = $params['common']; + + $clientModel = new ClientModel(); + $notificationModel = new NotificationModel(); + $clientRMModel = new ClientRMModel(); + $clientPolicyModel = new ClientPolicyModel(); + $PolicyPremium1Model = new PolicyPremium1Model(); + $PolicyPremium2Model = new PolicyPremium2Model(); + + + $client_data = $clientModel->where('id', $client_id)->first(); + + $params['client_data'] = $client_data; + + $notification_data = $notificationModel->where('client_id', $client_id)->where('template_name', $action)->first(); + + if (isset($notification_data) && $notification_data['enabled'] == 1) { + + $client_rm_data = $clientRMModel->where('client_id', $client_id)->where('is_active', 1)->findAll(); + $user_list = []; + foreach ($client_rm_data as $key => $value) { + if ($value['level'] == 3) { + $userModel = new UserModel(); + $user_data = $userModel->where('id', $value['user_id'])->first(); + $user_list[] = $user_data; + } + } + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + // $client_logo = $nhance_logo; + + $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content); + $mail_content = str_replace(["[[nhance_logo]]", "{{nhance_logo}}"], "Nhance Logo", $mail_content); + $mail_content = str_replace(["[[client_logo]]", "{{client_logo}}"], "Client Logo", $mail_content); + + $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content); + + // Step 1: Replace the placeholder with an HTML table structure + $mail = ''; + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $array_list = $params['array_list']; + $Addon_list = []; + + foreach ($array_list as $item) { + + $payable_employee_array = []; + + if (count($item) != 0) { + $table_content .= '

Policy Type :'; + $temp_data = ''; + $policy_name = ''; + $is_addon = ''; + + foreach ($item as $inner_item) { + + //getting policy premium data + $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + if ($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7) { + $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } else { + $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } + //end of getting policy premium data + + if ($inner_item['payable_employee'] == 1 && $client_policy_data['policy_type_id'] == 2) { + $payable_employee_array[] = $inner_item; + } + + $policy_name = $inner_item['policy_name']; + + if ($inner_item['relationship'] == 'Self') { + // $emp_code = ' (' . $inner_item['emp_code'] . ')'; + $emp_code = ' ( Employee Code : ' . $inner_item['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + $si = ''; + $premium = ''; + $gst_forself = ''; + // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + $si = '₹ ' . format_indian_number($inner_item['basic_cover_si']); + $premium = '₹ ' . format_indian_number(round($inner_item['premium'])); + $gst_forself = '₹ ' . format_indian_number(round($inner_item['gst'])); + // } + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . $emp_code . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '' . $si . ''; + + // Only Display SI Topup and Dependent Addon + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + } + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + } + + $policy_name_for_policy_type = $inner_item['policy_name']; + if ($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3) { + $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + } + + $table_content .= $policy_name_for_policy_type . '

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($is_addon == 2 || $is_addon == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + if ($is_addon == 2 || $is_addon == 3) { + $addon_list_array = [ + 'policy_name' => $policy_name_for_policy_type, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + } + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; + } + + if (count($payable_employee_array) > 0) { + + $table_content .= '

Policy Type :'; + $temp_data = ''; + $is_addon = ''; + + foreach ($payable_employee_array as $inner_item) { + + + //getting policy premium data + $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + if ($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7) { + $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } else { + $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } + //end of getting policy premium data + + + $si = ''; + $premium = ''; + $gst_forself = ''; + + $si = '₹ ' . format_indian_number($inner_item['basic_cover_si']); + $premium = '₹ ' . format_indian_number(round($inner_item['rata_premimum'])); + $gst_forself = '₹ ' . format_indian_number(round($inner_item['gst'])); + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '' . $si . ''; + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + + $policy_name_for_policy_type = $inner_item['policy_name']; + if ($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3) { + $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + } + + $table_content .= $policy_name_for_policy_type . ' ( Payable By Employee )

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + + $addon_list_array = [ + 'policy_name' => $policy_name_for_policy_type . '( Payable By Employee )', + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; + } + } + + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= ''; + + // Center align for table header and body + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $sum_total = 0; + foreach ($Addon_list as $key => $value) { + $total_addon = $value['gst'] + $value['addtional_premium']; + $sum_total += $total_addon; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + } + + $sum_total_words = numberToWords($sum_total); + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $value['policy_name'] . '₹' . format_indian_number($value['addtional_premium']) . '₹' . format_indian_number($value['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($sum_total) . '
'; + // $table_content .= '
' . $sum_total_words . '
'; + } + + + $mail_content = str_replace(["[[member_summary]]", "{{member_summary}}"], $table_content, $mail_content); + + $account_manager_mail_list = []; + if (isset($user_list)) { + foreach ($user_list as $key => $value) { + $full_name = $value['first_name'] . ' ' . $value['last_name']; + $mail_content = str_replace(["[[member_name]]", "{{member_name}}"], $full_name, $mail_content); + + $mail_content = preg_replace('/]*>( |\s)*<\/p>/i', '', $mail_content); + + $data['params'] = $params;$data['client_logo'] = $client_logo; + $data['mail_content'] = $mail_content; + $mail_content = view('mail_template', $data); + + + $wholeData[] = ['mail' => $value['email'], 'subject' => $subject, 'message' => $mail_content, 'reply_to' => $client_data['reply_to'], 'common' => $common]; + // $wholeData[] = ['mail' => $value['email'], 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'}}; + } + return $wholeData; + } + } + } //else if($action == 'client_hr_summary_mail'){ + + // $client_id = $params['client_id']; + // $client_policy_id = $params['client_policy_id']; + // $common = $params['common']; + // data: name: name: + // $clientModel = new ClientModel(); + // $clientPolicyModel = new ClientPolicyModel(); + // $PolicyPremium1Model = new PolicyPremium1Model(); + // $PolicyPremium2Model = new PolicyPremium2Model(); + + // $client_data =$clientModel->where('id', $client_id)->first(); + // $notificationModel = new NotificationModel(); + // $notification_data = $notificationModel->where('client_id' ,$client_id)->where('template_name', $action)->first(); + // $clientRMModel =new ClientRMModel(); + + // if (isset($notification_data['enabled']) && $notification_data['enabled'] == 1) { + + // $client_rm_data= $clientRMModel->where('client_id', $client_id)->where('is_active',1)->findAll(); + // $user_list= []; + // foreach ($client_rm_data as $key => $value) { + // if($value['level'] == 3){ + // $userModel = new UserModel(); + // $user_data = $userModel->where('id', $value['user_id'])->first(); + // $user_list[]=$user_data; + // } + // } + + + + // $mail_content = $notification_data['mail_content']; + // $subject = $notification_data['subject']; + // $app_link = $_ENV['App_Url']; + // $nhance_logo = $_ENV['NHANCE_LOGO']; + + // $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + // // $client_logo = $nhance_logo; + + // $mail_content = str_replace(["[[nhance_logo]]", "{{nhance_logo}}"], "Nhance Logo", $mail_content); + // $mail_content = str_replace(["[[client_logo]]", "{{client_logo}}"], "Client Logo", $mail_content); + // $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content); + + // $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content); + + // // Step 1: Replace the placeholder with an HTML table structure + // $mail = ''; + // $table_content = ''; + // $addtional_premium = 0; + // $gst = 0; + // $array_list = $params['array_list']; + // $Addon_list = []; + + // foreach ($array_list as $item) { + + // $payable_employee_array = []; + + // if (count($item) != 0) { + // $table_content .= '

Policy Type :'; + // $temp_data = ''; + // $policy_name = ''; + // $is_addon = ''; + + // foreach ($item as $inner_item) { + + // //getting policy premium data + // $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + // if($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7 ){ + // $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + // }else{ + // $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + // } + // //end of getting policy premium data + + // if($inner_item['payable_employee'] == 1 && $client_policy_data['policy_type_id'] == 2){ + // $payable_employee_array[] = $inner_item; + // } + + // $policy_name = $inner_item['policy_name']; + + // if ($inner_item['relationship'] == 'Self') { + // $emp_code = ' (' . $inner_item['emp_code'] . ')'; + // } else { + // $emp_code = ''; + // } + + // $si = ''; + // $premium = ''; + // $gst_forself = ''; + + // // dd($policy_premium_data, $client_policy_data, $inner_item); + + // // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + // $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); + // $premium = '₹ ' .format_indian_number(round($inner_item['premium'])); + // $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); + // // } + + // $temp_data .= ''; + // $temp_data .= '' . $inner_item['name'] . $emp_code . ''; + // $temp_data .= '' . $inner_item['relationship'] . ''; + // $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + // $temp_data .= '' . $si . ''; + + // // Only Display SI Topup and Dependent Addon + // if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + // $temp_data .= '' . $premium . ''; + // $temp_data .= '' . $gst_forself . ''; + // } + + // $temp_data .= ''; + + // $is_addon = $inner_item['is_addon']; + + // if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + // $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + // $gst = $inner_item['gst'] + $gst; + // } + // } + + // $policy_name_for_policy_type = $inner_item['policy_name']; + // if($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3){ + // $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + // } + + // $table_content .= $policy_name_for_policy_type . '

'; + // $table_content .= ''; + + // // Add text-align: center to the table head + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + + // // Only Display SI Topup and Dependent Addon + // if ($is_addon == 2 || $is_addon == 3) { + // $table_content .= ''; + // $table_content .= ''; + // } + + // $table_content .= ''; + // $table_content .= ''; + + // // Add text-align: center to the table body + // $table_content .= '' . $temp_data . ''; + // $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + // if ($is_addon == 2 || $is_addon == 3) { + // $addon_list_array = [ + // 'policy_name' => $policy_name_for_policy_type, + // 'addtional_premium' => round($addtional_premium), + // 'gst' => round($gst) + // ]; + // $Addon_list[] = $addon_list_array; + // } + + // $temp_data = ''; + // $addtional_premium = 0; + // $gst = 0; + // } + + // if(count($payable_employee_array) > 0){ + + // $table_content .= '

Policy Type :'; + // $temp_data = ''; + // $is_addon = ''; + + // foreach ($payable_employee_array as $inner_item) { + + + // //getting policy premium data + // $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + // if($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7 ){ + // $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + // }else{ + // $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + // } + // //end of getting policy premium data + + + // $si = ''; + // $premium = ''; + // $gst_forself = ''; + + // $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); + // $premium = '₹ ' .format_indian_number(round($inner_item['rata_premimum'])); + // $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); + + // $temp_data .= ''; + // $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; + // $temp_data .= '' . $inner_item['relationship'] . ''; + // $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + // $temp_data .= '' . $si . ''; + // $temp_data .= '' . $premium . ''; + // $temp_data .= '' . $gst_forself . ''; + + // $temp_data .= ''; + + // $is_addon = $inner_item['is_addon']; + + // $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + // $gst = $inner_item['gst'] + $gst; + // } + + // $policy_name_for_policy_type = $inner_item['policy_name']; + // if($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3){ + // $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + // } + + // $table_content .= $policy_name_for_policy_type . ' ( Payable By Employee )

'; + // $table_content .= ''; + + // // Add text-align: center to the table head + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + + // $table_content .= ''; + // $table_content .= ''; + + // // Add text-align: center to the table body + // $table_content .= '' . $temp_data . ''; + // $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + + // $addon_list_array = [ + // 'policy_name' => $policy_name_for_policy_type . '( Payable By Employee )', + // 'addtional_premium' => round($addtional_premium), + // 'gst' => round($gst) + // ]; + // $Addon_list[] = $addon_list_array; + + + // $temp_data = ''; + // $addtional_premium = 0; + // $gst = 0; + + // } + // } + + // if (count($Addon_list) > 0) { + // $table_content .= '
'; + // $table_content .= ''; + + // // Center align for table header and body + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + + // $table_content .= ''; + + // $sum_total = 0; + // foreach ($Addon_list as $key => $value) { + // $total_addon = $value['gst'] + $value['addtional_premium']; + // $sum_total += $total_addon; + + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // } + + // $sum_total_words = numberToWords($sum_total); + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= ''; + // $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $value['policy_name'] . '₹' . format_indian_number($value['addtional_premium']) . '₹' . format_indian_number($value['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($sum_total) . '
'; + // // $table_content .= '
' . $sum_total_words . '
'; + // } + + // $mail_content = str_replace(["[[member_summary]]", "{{member_summary}}"], $table_content , $mail_content); + + + // $hr_mails = $client_data['hr_mails']; + // $mail_array = explode(',', $hr_mails); + // $mail_array = array_map('trim', $mail_array); + // $wholeData = []; + // foreach ($mail_array as $key => $value) { + // + // + // $mail_content = preg_replace('/]*>( |\s)*<\/p>/i', '', $mail_content); + + // $data['params'] = $params;$data['client_logo'] = $client_logo; + // $data['mail_content'] = $mail_content; + // $mail_content = view('mail_template',$data); + // $mail_content = $header_of_mail . + // '
+ // + + // + // + // + //
+ // ' . $mail_content . ' + //
+ //
' . $footer_of_mail; + + // $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to'], 'common' => $common]; + // // $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'}}; + // } + + // return $wholeData; + // } + + // } + } + + public static function sendMailNotification_old($action, $params) + { + $wholeData = []; + + if ($action == 'member_welcome_mail') { + + $dataToInsert = $params['dataToInsert']; + $notification = $params['notification']; + $client_data = $params['client_data']; + $common = $params['common']; + + $mailAttachmentModel = new MailAttachmentModel(); + $attachment_data = $mailAttachmentModel + ->select('file_path, file_name') + ->where('notification_id', $notification['id']) + ->where('is_active', 1) + ->findAll(); + + $attachments = []; + foreach ($attachment_data as $data) { + $attachments[] = [ + "filePath" => WRITEPATH . $data['file_path'], + "fileName" => $data['file_name'] + ]; + } + + $mail = $dataToInsert['email_corporate']; + $subject = $notification['subject']; + $app_link = $_ENV['App_Url']; + $employee_name = $dataToInsert['name']; + $employee_mobile_no = $dataToInsert['mobile']; + $mail_content = $notification['mail_content']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $enrollment_open_date = !empty($params['enrollment_open_date'] ?? null) + ? change_date_format($params['enrollment_open_date'], 'Y-m-d', 'F d, Y') + : 'N/A'; + + $enrollment_close_date = !empty($params['enrollment_close_date'] ?? null) + ? change_date_format($params['enrollment_close_date'], 'Y-m-d', 'F d, Y') + : 'N/A'; + + $mail_content = str_replace(["[[client_logo]]", "{{client_logo}}"], "Client Logo", $mail_content); + $mail_content = str_replace(["[[nhance_logo]]", "{{nhance_logo}}"], "Nhance Logo", $mail_content); + $mail_content = str_replace(["[[member_name]]", "{{member_name}}"], $employee_name, $mail_content); + $mail_content = str_replace(["[[member_mobile]]", "{{member_mobile}}"], $employee_mobile_no, $mail_content); + $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content); + + $mail_content = str_replace(["[[enrollment_open_date]]", "{{enrollment_open_date}}"], $enrollment_open_date, $mail_content); + $mail_content = str_replace(["[[enrollment_close_date]]", "{{enrollment_close_date}}"], $enrollment_close_date, $mail_content); + + $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content); + if ($dataToInsert['relationship'] == 'Self' && $mail != null || $mail != '') { + + + + $mail_content = preg_replace('/]*>( |\s)*<\/p>/i', '', $mail_content); + + $data['params'] = $params;$data['client_logo'] = $client_logo; + $data['mail_content'] = $mail_content; + $mail_content = view('mail_template', $data); + + + $wholeData = ['mail' => $mail, 'subject' => $subject, 'message' => $mail_content, 'bcc' => $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'attachments' => $attachments, 'common' => $common]; + } + + return $wholeData; + } else if ($action == 'member_reminder_mail') { + + $EmployeeModel = new EmployeeModel(); + $emp_data = $params['emp_data']; + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $common = $params['common']; + + $mailAttachmentModel = new MailAttachmentModel(); + $attachment_data = $mailAttachmentModel + ->select('file_path, file_name') + ->where('notification_id', $notification_data['id']) + ->where('is_active', 1) + ->findAll()??[]; + + $attachments = []; + foreach ($attachment_data as $data) { + $attachments[] = [ + "filePath" => WRITEPATH . $data['file_path'], + "fileName" => $data['file_name'] + ]; + } + + $subject = $notification_data['subject']; + + $app_link = env('App_Url'); + $mail_content = $notification_data['mail_content']; + $nhance_logo = env('NHANCE_LOGO'); + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + + $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content); + $mail_content = str_replace(["[[nhance_logo]]", "{{nhance_logo}}"], "Nhance Logo", $mail_content); + $mail_content = str_replace(["[[client_logo]]", "{{client_logo}}"], "Client Logo", $mail_content); + $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content); + $mail_content = str_replace(["[[policy_no]]", "{{policy_no}}"], $emp_data['policy_no'] ?? '', $mail_content); + $mail_content = str_replace(["[[emp_code]]", "{{emp_code}}"], $emp_data['emp_code'] ?? '', $mail_content); + $mail_content = str_replace(["[[employee_name]]", "{{employee_name}}"], $emp_data['name'] ?? '', $mail_content); + $mail_content = str_replace(["[[employee_mobile]]", "{{employee_mobile}}"], $emp_data['mobile'] ?? '', $mail_content); + //convert to dd-mm-yyyy format + $emp_data['enrollment_open_date'] = date('d-m-Y', strtotime($emp_data['enrollment_open_date'])); + $emp_data['enrollment_close_date'] = date('d-m-Y', strtotime($emp_data['enrollment_close_date'])); + $mail_content = str_replace(["[[enrollment_open_date]]", "{{enrollment_open_date}}"], $emp_data['enrollment_open_date'] ?? '', $mail_content); + $mail_content = str_replace(["[[enrollment_close_date]]", "{{enrollment_close_date}}"], $emp_data['enrollment_close_date'] ?? '', $mail_content); + + + + $employee_name = $emp_data['name'] ?? ''; + $employee_mobile_no = $emp_data['mobile'] ?? ''; + $mail_content = str_replace(["[[member_name]]", "{{member_name}}"], $employee_name, $mail_content); + $mail_content = str_replace(["[[member_mobile]]", "{{member_mobile}}"], $employee_mobile_no, $mail_content); + $mail = $emp_data['email_corporate'] ?? ''; + + + + $mail_content = preg_replace('/]*>( |\s)*<\/p>/i', '', $mail_content); + + $data['params'] = $params;$data['client_logo'] = $client_logo; + $data['mail_content'] = $mail_content; + $mail_content = view('mail_template', $data); + + + $wholeData = ['mail' => $mail, 'subject' => $subject, 'message' => $mail_content, 'bcc' => $client_data['common_mails'], 'attachments' => $attachments, 'reply_to' => $client_data['reply_to'], 'common' => $common]; + + return $wholeData; + } else if ($action == 'member_ecard_mail') { + + $notification = $params['notification']; + $get_emp_email_and_other_details = $params['get_emp_email_and_other_details']; + $rand_string = $params['rand_string']; + $client_data = $params['client_data']; + $tpa_id = $params['tpa_id']; + $common = $params['common']; + + + $mail_content = $notification['mail_content']; + $mail = $get_emp_email_and_other_details['email_corporate']; + $subject = $notification['subject']; + + $cleanedText = mb_convert_encoding($subject, 'UTF-8', 'UTF-8'); // Normalize encoding + $cleanedText = preg_replace('/[^\x20-\x7E]/', '', $cleanedText); + + $subject = $cleanedText; + + $link = generate_download_link($rand_string) . '/1'; + + $app_link = $_ENV['App_Url']; + $name = $get_emp_email_and_other_details['name']; + $employee_mobile_no = $get_emp_email_and_other_details['mobile']; + $mail_content = $notification['mail_content']; + + $nhance_logo = $_ENV['NHANCE_LOGO']; + // dd("3333333333333"); + + $post_enrollment_app_link = $_ENV['POST_ENROLLMENT_APP_LINK']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + // $client_logo = $nhance_logo; + + $mail_content = str_replace(["[[nhance_logo]]", "{{nhance_logo}}"], "Nhance Logo", $mail_content); + $mail_content = str_replace(["[[client_logo]]", "{{client_logo}}"], "Client Logo", $mail_content); + + $mail_content = str_replace(["[[member_name]]", "{{member_name}}"], $name, $mail_content); + $mail_content = str_replace(["[[member_mobile]]", "{{member_mobile}}"], $employee_mobile_no, $mail_content); + $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content); + $mail_content = str_replace(["[[post_enrollment_app_link]]", "{{post_enrollment_app_link}}"], "Review Details", $mail_content); + // $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content); + $mail_content = str_replace(["[[ecard_download_link]]", "{{ecard_download_link}}"], "Download Insurance Card", $mail_content); + $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content); + + + $mail_content = preg_replace('/]*>( |\s)*<\/p>/i', '', $mail_content); $data['params'] = $params;$data['client_logo'] = $client_logo; @@ -1465,6 +2715,16 @@ class sendMailNotification $mobile = $array_list['mobile']; $emp_code = ''; + $clientPolicyModel = new ClientPolicyModel(); + $sample_policy = $clientPolicyModel + ->where('client_id', $client_data['id'] ?? 0) + ->where('is_active', 1) + ->first(); + $is_premium_summery = (int) ($sample_policy['is_premium_summery'] ?? 1); + $show_premium_columns = ($is_premium_summery === 1); + $include_addon_summary = in_array($is_premium_summery, [1, 2], true); + $show_full_premium_breakdown = ($is_premium_summery === 1); + if (!empty($array_list)) { $table_content .= '

Policy Type :'; @@ -1489,7 +2749,7 @@ class sendMailNotification $table_content .= 'Sum Insured'; // Only Display SI Topup and Dependent Addon - if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + if (($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) && $show_premium_columns) { $table_content .= 'Premium'; $table_content .= 'GST'; } @@ -1505,7 +2765,7 @@ class sendMailNotification $table_content .= '' . \DateTime::createFromFormat('Y-m-d', $array_list['dob'])->format('d-m-Y') . ''; $table_content .= '₹' . format_indian_number($array_list['basic_cover_si']) . ''; - if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + if (($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) && $show_premium_columns) { $table_content .= '₹' . format_indian_number(round($array_list['premium'])) . ''; $table_content .= '₹' . format_indian_number(round($array_list['gst'])) . ''; } @@ -1515,7 +2775,7 @@ class sendMailNotification $table_content .= '

'; // Calculate additional premium and GST if applicable - if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + if (($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) && $include_addon_summary) { $addtional_premium = $array_list['rata_premimum']; $gst = $array_list['gst']; @@ -1537,9 +2797,13 @@ class sendMailNotification $table_content .= ''; $table_content .= ''; $table_content .= 'Policy Name'; - $table_content .= 'Additional Premium'; - $table_content .= 'GST'; - $table_content .= 'Total'; + if ($show_full_premium_breakdown) { + $table_content .= 'Additional Premium'; + $table_content .= 'GST'; + } + // is_premium_summery == 2: label as Total Premium + $total_label = $show_full_premium_breakdown ? 'Total' : 'Total Premium'; + $table_content .= '' . $total_label . ''; $table_content .= ''; $table_content .= ''; @@ -1548,14 +2812,20 @@ class sendMailNotification $total_addon = $Addon_list[0]['gst'] + $Addon_list[0]['addtional_premium']; $table_content .= ''; $table_content .= '' . $Addon_list[0]['policy_name'] . ''; - $table_content .= '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . ''; - $table_content .= '₹' . format_indian_number($Addon_list[0]['gst']) . ''; + if ($show_full_premium_breakdown) { + $table_content .= '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . ''; + $table_content .= '₹' . format_indian_number($Addon_list[0]['gst']) . ''; + } $table_content .= '₹' . format_indian_number($total_addon) . ''; $table_content .= ''; $sum_total_words = numberToWords($total_addon); $table_content .= ''; - $table_content .= 'Total'; + if ($show_full_premium_breakdown) { + $table_content .= 'Total'; + } else { + $table_content .= '' . $total_label . ''; + } $table_content .= '₹' . format_indian_number($total_addon) . ''; $table_content .= ''; $table_content .= '';