350 lines
13 KiB
PHP
350 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Models\EmployeePolicyModel;
|
|
use App\Models\InsurerBranchModel;
|
|
use App\Models\RFQModel;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use CodeIgniter\API\ResponseTrait;
|
|
use Dompdf\Dompdf;
|
|
use Dompdf\Options;
|
|
|
|
class TestingController extends BaseController
|
|
{
|
|
use ResponseTrait;
|
|
protected $myLogger;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->myLogger = \Config\Services::mylogger();
|
|
}
|
|
|
|
public function saveForm()
|
|
{
|
|
// Get JSON input
|
|
$data = $this->request->getPost();
|
|
|
|
// For testing: just return the received data
|
|
return $this->respond([
|
|
'status' => 'success',
|
|
'message' => 'Form data received successfully!',
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
public function testcli()
|
|
{
|
|
echo "hi";
|
|
$this->myLogger->logme('error', "test log");
|
|
echo "hi 2";
|
|
log_message('error', 'test message for log_message_function');
|
|
echo "hi 3";
|
|
}
|
|
|
|
|
|
public function generatePDF()
|
|
{
|
|
// Sample data - replace with your actual data source
|
|
$data = [
|
|
'NAME' => 'John Doe',
|
|
'GENDER' => 'Male',
|
|
'DOB' => '01/01/1990',
|
|
'RELATION' => 'Self',
|
|
'POLICY_NO' => 'POL123456789',
|
|
'TPA_ID' => 'TPA987654321',
|
|
'POLICY_START_DATE' => '01/01/2024',
|
|
'POLICY_DATE' => '31/12/2024',
|
|
'INSURER_NAME' => 'ABC Insurance Co.',
|
|
'TPA_NAME' => 'XYZ TPA Ltd.',
|
|
'FRONT_CARD' => base_url('assets/images/front-card.jpg'), // Your card images
|
|
'BACK_CARD' => base_url('assets/images/back-card.jpg'),
|
|
'LEVELS' => 'Level 1: 1800-XXX-XXXX<br>Level 2: support@company.com'
|
|
];
|
|
|
|
// Load the HTML template
|
|
$html = $this->loadTemplate($data);
|
|
|
|
// Configure DomPDF options
|
|
$options = new Options();
|
|
$options->set('isRemoteEnabled', true); // Enable loading of remote images
|
|
$options->set('isHtml5ParserEnabled', true);
|
|
$options->set('isPhpEnabled', true);
|
|
$options->set('debugPng', false);
|
|
$options->set('debugKeepTemp', false);
|
|
$options->set('debugCss', false);
|
|
$options->set('debugLayout', false);
|
|
$options->set('debugLayoutLines', false);
|
|
$options->set('debugLayoutBlocks', false);
|
|
$options->set('debugLayoutInline', false);
|
|
$options->set('debugLayoutPaddingBox', false);
|
|
|
|
// Initialize DomPDF
|
|
$dompdf = new Dompdf($options);
|
|
|
|
// Load HTML content
|
|
$dompdf->loadHtml($html);
|
|
|
|
// Set paper size and orientation
|
|
$dompdf->setPaper('A4', 'landscape'); // or 'portrait'
|
|
|
|
// Render PDF
|
|
$dompdf->render();
|
|
|
|
// Output PDF to browser
|
|
$filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf';
|
|
$dompdf->stream($filename, ['Attachment' => true]); // Set to false for inline view
|
|
}
|
|
|
|
public function viewPDF()
|
|
{
|
|
// Same as generatePDF but with inline view
|
|
$data = [
|
|
'NAME' => 'Korukonda Naga Venkata Ramalinga Satya Swarna Kumari',
|
|
'GENDER' => 'Male',
|
|
'DOB' => '01/01/1990',
|
|
'RELATION' => 'Self',
|
|
'POLICY_NO' => '97000034230400000109_EX_Parental',
|
|
'TPA_ID' => 'TPA987654321',
|
|
'POLICY_START_DATE' => '01/01/2024',
|
|
'POLICY_DATE' => '31/12/2024',
|
|
'INSURER_NAME' => 'ZURICH KOTAK GTNERAL INSURANCE COIIPANY lNDlA LIMITED',
|
|
'TPA_NAME' => 'HealthIndia Insurance TPA Services Pvt. Ltd.',
|
|
'FRONT_CARD' => base_url() .('public/uploads/template_bg/Nhance_Ecard_working_1_front_3.png'),
|
|
'BACK_CARD' => base_url() . ('public/uploads/template_bg/Nhance_Ecard_working_1_Back_3.png'),
|
|
'LEVELS' => 'Level 1: 1800-XXX-XXXX<br>Level 2: support@company.com'
|
|
];
|
|
|
|
$data2 = [
|
|
'NAME' => 'John Doe',
|
|
'GENDER' => 'Male',
|
|
'DOB' => '01/01/1990',
|
|
'RELATION' => 'Self',
|
|
'POLICY_NO' => 'POL123456789',
|
|
'TPA_ID' => 'TPA987654321',
|
|
'POLICY_START_DATE' => '01/01/2024',
|
|
'POLICY_DATE' => '31/12/2024',
|
|
'INSURER_NAME' => 'ABC Insurance Co.',
|
|
'TPA_NAME' => 'XYZ TPA Ltd.',
|
|
'FRONT_CARD' => base_url() .('public/uploads/template_bg/Nhance_Ecard_working_1_front_3.png'),
|
|
'BACK_CARD' => base_url() . ('public/uploads/template_bg/Nhance_Ecard_working_1_Back_3.png'),
|
|
'LEVELS' => 'Level 1: 1800-XXX-XXXX<br>Level 2: support@company.com'
|
|
];
|
|
|
|
$employeeController = new EmployeeController();
|
|
// $html = $employeeController->generateIDCardForEmployeeUsingDom('LfpH3R');
|
|
$html = $this->loadTemplate($data2);
|
|
// print_r($html); die;
|
|
$options = new Options();
|
|
$options->set('isRemoteEnabled', true);
|
|
$options->set('isHtml5ParserEnabled', true);
|
|
|
|
$dompdf = new Dompdf($options);
|
|
// $dompdf->loadHtml($html);
|
|
$dompdf->loadHtml('<style>@page { margin: 0; }</style>' . $html);
|
|
$dompdf->setPaper('A4', 'portrait');
|
|
// $dompdf->setPaper('A4', 'landscape');
|
|
$dompdf->render();
|
|
|
|
$filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf';
|
|
// $dompdf->stream($filename, ['Attachment' => true]); // Inline view
|
|
$dompdf->stream($filename, ['Attachment' => false]); // Force download
|
|
|
|
}
|
|
|
|
private function loadTemplate($data)
|
|
{
|
|
// Load your HTML template
|
|
$template = file_get_contents(WRITEPATH . 'e_card_template/common.html');
|
|
|
|
// Replace placeholders with actual data
|
|
foreach ($data as $key => $value) {
|
|
$template = str_replace('{' . $key . '}', $value, $template);
|
|
}
|
|
|
|
return $template;
|
|
}
|
|
|
|
// not using and not working
|
|
public function viewPdfUsingMpdf()
|
|
{
|
|
$data = [
|
|
'NAME' => 'Korukonda Naga Venkata Ramalinga Satya Swarna Kumari',
|
|
'GENDER' => 'Male',
|
|
'DOB' => '01/01/1990',
|
|
'RELATION' => 'Self',
|
|
'POLICY_NO' => '97000034230400000109_EX_Parental',
|
|
'TPA_ID' => 'TPA987654321',
|
|
'POLICY_START_DATE' => '01/01/2024',
|
|
'POLICY_DATE' => '31/12/2024',
|
|
'INSURER_NAME' => 'ZURICH KOTAK GTNERAL INSURANCE COIIPANY lNDlA LIMITED',
|
|
'TPA_NAME' => 'HealthIndia Insurance TPA Services Pvt. Ltd.',
|
|
'FRONT_CARD' => base_url('public/uploads/template_bg/Nhance_Ecard_working_1_front_3.png'),
|
|
'BACK_CARD' => base_url('public/uploads/template_bg/Nhance_Ecard_working_1_Back_3.png'),
|
|
'LEVELS' => 'Level 1: 1800-XXX-XXXX<br>Level 2: support@company.com'
|
|
];
|
|
|
|
$html = $this->loadTemplate($data);
|
|
|
|
// Load mPDF
|
|
$mpdf = "";
|
|
|
|
// $mpdf = new \Mpdf\Mpdf([
|
|
// 'mode' => 'utf-8',
|
|
// 'format' => 'A4',
|
|
// 'margin_left' => 0,
|
|
// 'margin_right' => 0,
|
|
// 'margin_top' => 0,
|
|
// 'margin_bottom' => 0,
|
|
// 'tempDir' => __DIR__ . '/writable/mpdf'
|
|
// ]);
|
|
|
|
// Optional: Stretch background or images fully
|
|
// $html = '
|
|
// <style>
|
|
// body { margin:0; padding:0; }
|
|
// @page { margin:0; }
|
|
// </style>' . $html;
|
|
|
|
// $mpdf->WriteHTML($html);
|
|
|
|
// // Output inline (no download prompt)
|
|
// $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf';
|
|
// $mpdf->Output($filename, 'D');
|
|
/*
|
|
'I' = inline view in browser (no download prompt).
|
|
'D' = force download.
|
|
'F' = save to file.
|
|
'S' = return as string.
|
|
*/
|
|
}
|
|
|
|
public function getEmployeePolicyTypes($client_id, $emp_code, $emp_id)
|
|
{
|
|
$employeePolicy = new EmployeePolicyModel();
|
|
|
|
$data = $employeePolicy
|
|
->select('client_policy.policy_type_id')
|
|
->join('employees', 'employee_polices.employee_id = employees.id')
|
|
->join('client_policy', 'employee_polices.client_policy_id = client_policy.id')
|
|
->where('employees.is_active', 1)
|
|
->where('employees.emp_status', ['active', 'expired'])
|
|
->where('employee_polices.is_active', 1)
|
|
->where('employee_polices.status', ['active', 'expired'])
|
|
->where('employees.client_id', $client_id)
|
|
->where('employees.emp_code', $emp_code)
|
|
->groupBy('employee_polices.client_policy_id')
|
|
->findAll();
|
|
|
|
}
|
|
|
|
public function ptedfitdata($id){
|
|
$policy_transaction = new PolicyTransactionController();
|
|
$data = $policy_transaction->getInceptionDataForEdit($id);
|
|
// dd($data);
|
|
$insurerBranchModel = new InsurerBranchModel();
|
|
$insurer_branch = $insurerBranchModel->getInsurerBranchesWithInsurerNames();
|
|
|
|
$dataArray = $data['pt_co_share_details']; // Example
|
|
$cd_ac_pk = 'CD12345';
|
|
$role_id = 1;
|
|
$team_id = ['6'];
|
|
$insurer_branch = $insurer_branch;
|
|
|
|
return view('pt_calc_table', [
|
|
'dataArray' => $dataArray,
|
|
'cd_ac_pk' => $cd_ac_pk,
|
|
'role_id' => $role_id,
|
|
'team_id' => $team_id,
|
|
'insurer_branch' => $insurer_branch
|
|
]);
|
|
}
|
|
|
|
function generateInsurerTable($dataArray, $cd_ac_pk, $role_id, $team_id, $insurer_branch)
|
|
{
|
|
$html = '<table id="insurerTable" class="table table-bordered"><tbody>';
|
|
|
|
foreach ($dataArray as $index => $data) {
|
|
$disable_td = ($data['record_count'] > 0) ? 'readonly-select' : '';
|
|
$insurer = $data['insurer_branch_id'] . '-' . $data['insurer_id'];
|
|
|
|
$html .= '<tr id="table_tr_' . ($index + 1) . '">';
|
|
|
|
// Insurer selection
|
|
$html .= '<td><select class="form-control follow_insurer ' . $disable_td . '" name="follow_insurer_id[]">';
|
|
$html .= '<option value="">Select Insurer</option>';
|
|
foreach ($insurer_branch as $value) {
|
|
$selected = ($insurer == ($value['id'] . '-' . $value['insurer_id'])) ? 'selected' : '';
|
|
$html .= '<option value="' . $value['id'] . '-' . $value['insurer_id'] . '" ' . $selected . '>'
|
|
. $value['insurer_name'] . '-' . $value['branch_code'] . '</option>';
|
|
}
|
|
$html .= '</select></td>';
|
|
|
|
// Leader toggle
|
|
$checked = ($data['co_share_type'] == 1) ? 'checked' : '';
|
|
$html .= '<td><input type="checkbox" class="' . $disable_td . '" name="co_share_type[]" ' . $checked . '></td>';
|
|
|
|
// CD Account
|
|
$html .= '<td><select class="form-control follow_insurer_cd ' . $disable_td . '" name="cd_ac_no_for_child[]">';
|
|
$html .= '<option value="">Select CD No</option>';
|
|
$html .= '<option value="add_cd">+ Add CD No</option>';
|
|
if ($cd_ac_pk) {
|
|
$html .= '<option value="' . $cd_ac_pk . '" selected>' . $cd_ac_pk . '</option>';
|
|
}
|
|
$html .= '</select></td>';
|
|
|
|
// CD Amount
|
|
$html .= '<td><input type="text" readonly value="' . htmlspecialchars($data['cd_amount'] ?? '') . '"></td>';
|
|
|
|
// Example of follower policy no
|
|
$html .= '<td><input type="text" class="' . $disable_td . '" value="' . htmlspecialchars($data['follower_policy_no']) . '"></td>';
|
|
|
|
// Add other fields (bp_amt, tp_amt, gst, etc.)
|
|
$html .= '<td><input type="text" class="' . $disable_td . '" value="' . htmlspecialchars($data['bp_amt']) . '"></td>';
|
|
$html .= '<td><input type="text" class="' . $disable_td . '" value="' . htmlspecialchars($data['tp_amt']) . '"></td>';
|
|
$html .= '<td><input type="text" class="' . $disable_td . '" value="' . htmlspecialchars($data['tep_amt']) . '"></td>';
|
|
$html .= '<td><input type="hidden" name="co_share_id[]" value="' . htmlspecialchars($data['id']) . '"></td>';
|
|
|
|
$html .= '</tr>';
|
|
}
|
|
|
|
$html .= '</tbody></table>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
public function viewRFQNonEb()
|
|
{
|
|
$insurerBranchModel = new InsurerBranchModel();
|
|
$data['page_name'] = "RFQ NON EB";
|
|
$data['insurer'] = $insurerBranchModel->getInsurerBranchesWithInsurerNames();
|
|
// dd($data);
|
|
return $this->loadLayout('view_rfq_non_eb_new', $data);
|
|
}
|
|
|
|
public function saverfq(){
|
|
$json = $this->request->getPost('json');
|
|
$json = json_encode($json);
|
|
print_r($json);
|
|
|
|
// $data['lead_id'] = 10000;
|
|
// $data['json'] = $json;
|
|
// $rfq = new RFQModel();
|
|
|
|
// $rfq->insert($data);
|
|
}
|
|
|
|
public function exportExcel()
|
|
{
|
|
$rfq = new RFQModel();
|
|
$policy_data = $rfq->where('lead_id', 10000)->first();
|
|
// print_rr($policy_data['json']); die;
|
|
$policy_data = json_decode($policy_data['json'], true);
|
|
$policy_data = array_slice($policy_data, 0, -2);
|
|
print_rr($policy_data); die;
|
|
dd($policy_data);
|
|
}
|
|
|
|
}
|