MERGE_UAT_BUG_FIXES
This commit is contained in:
commit
5f14099d24
@ -501,6 +501,8 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
|
||||
|
||||
$routes->group("inception", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->match(['get', 'post'], 'list', 'PolicyTransactionController::viewInception');
|
||||
$routes->post('list/datatable', 'PolicyTransactionController::inceptionListDataTable');
|
||||
$routes->post('list/clear-cache', 'PolicyTransactionController::clearInceptionListCache');
|
||||
$routes->post("create", "PolicyTransactionController::createInceptionPolicy");
|
||||
$routes->get("list/(:any)", "PolicyTransactionController::getInceptionDataForEdit/$1");
|
||||
$routes->get("remove/(:any)", "PolicyTransactionController::removeCDMaster/$1");
|
||||
@ -511,6 +513,8 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
|
||||
|
||||
$routes->group("endorsement", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->get("list", "PolicyTransactionController::viewEndorsement");
|
||||
$routes->post("list/datatable", "PolicyTransactionController::endorsementListDataTable");
|
||||
$routes->post("list/clear-cache", "PolicyTransactionController::clearEndorsementListCache");
|
||||
$routes->post("create", "PolicyTransactionController::createEndorsementPolicy");
|
||||
$routes->get("list/(:any)", "PolicyTransactionController::getEndorsementDataForEdit/$1");
|
||||
$routes->get("remove/(:any)", "PolicyTransactionController::removeCDMaster/$1");
|
||||
@ -520,6 +524,8 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
|
||||
|
||||
$routes->group("report", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->match(['get', 'post'],"list", "PolicyTransactionController::reportBDS");
|
||||
$routes->post("list/datatable", "PolicyTransactionController::reportBDSDataTable");
|
||||
$routes->post("list/clear-cache", "PolicyTransactionController::clearReportBDSCache");
|
||||
$routes->match(['get', 'post'],"list_new", "PolicyTransactionController::reportBDSNew");
|
||||
$routes->get("report-varience-list", "PolicyTransactionController::reportVarience");
|
||||
$routes->get("report-business-list", "PolicyTransactionController::reportBusinessList");
|
||||
|
||||
@ -602,59 +602,9 @@ class PolicyTransactionController extends BaseController
|
||||
'policy_end_date' => 'Policy End Date',
|
||||
];
|
||||
|
||||
// Filter data
|
||||
$start_date = $this->request->getGet('start_date');
|
||||
$end_date = $this->request->getGet('end_date');
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$insurer_id = $this->request->getGet('insurer_id');
|
||||
$policy_type_id = $this->request->getGet('policy_type_id');
|
||||
$date_type = $this->request->getGet('date_type');
|
||||
$issuer = $this->request->getGet('issuer');
|
||||
$status = $this->request->getGet('status');
|
||||
|
||||
// Handle null or empty values
|
||||
$start_date = empty($start_date) ? 0 : $start_date;
|
||||
$end_date = empty($end_date) ? 0 : $end_date;
|
||||
$client_id = empty($client_id) ? 0 : $client_id;
|
||||
$insurer_id = empty($insurer_id) ? 0 : $insurer_id;
|
||||
$policy_type_id = empty($policy_type_id) ? 0 : $policy_type_id;
|
||||
$date_type = empty($date_type) ? 0 : $date_type;
|
||||
$issuer = empty($issuer) ? 0 : $issuer;
|
||||
$status = empty($status) ? 0 : $status; // Corrected from `$issuer`
|
||||
|
||||
if(empty($bds_edit_pt_id) && empty($view)){
|
||||
if ($this->request->is('get')) {
|
||||
|
||||
// Fetch inception data list
|
||||
$data['inception_data_list'] = $this->policyTransactionModel->getInceptionTranctionListData(
|
||||
$start_date,
|
||||
$end_date,
|
||||
$client_id,
|
||||
$insurer_id,
|
||||
$policy_type_id,
|
||||
$date_type,
|
||||
$issuer,
|
||||
$status
|
||||
);
|
||||
} else {
|
||||
|
||||
$ids = $this->request->getPost('ids');
|
||||
$ids = array_filter(explode(',', $ids));
|
||||
$data['inception_data_list'] = $this->policyTransactionModel->getInceptionTranctionListData(
|
||||
$start_date = 0,
|
||||
$end_date = 0,
|
||||
$client_id = 0,
|
||||
$insurer_id = 0,
|
||||
$policy_type_id = 0,
|
||||
$date_type = 0,
|
||||
$issuer = 0,
|
||||
$status = 0,
|
||||
$ids
|
||||
);
|
||||
}
|
||||
}else{
|
||||
$data['inception_data_list'] = [];
|
||||
}
|
||||
// List rows are loaded via server-side DataTables AJAX.
|
||||
$data['inception_data_list'] = [];
|
||||
$data['inception_filters'] = $this->buildInceptionFiltersFromRequest();
|
||||
|
||||
|
||||
|
||||
@ -746,6 +696,136 @@ class PolicyTransactionController extends BaseController
|
||||
$this->loadLayout('policy_transaction_inception_list', $data);
|
||||
}
|
||||
|
||||
public function inceptionListDataTable()
|
||||
{
|
||||
if (!$this->request->isAJAX()) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Invalid request.',
|
||||
]);
|
||||
}
|
||||
|
||||
$draw = (int) ($this->request->getPost('draw') ?? 0);
|
||||
$start = max(0, (int) ($this->request->getPost('start') ?? 0));
|
||||
$length = (int) ($this->request->getPost('length') ?? 10);
|
||||
$search = trim((string) ($this->request->getPost('search')['value'] ?? ''));
|
||||
|
||||
$filters = $this->buildInceptionFiltersFromRequest();
|
||||
$result = $this->policyTransactionModel->getInceptionTranctionListDataTable(
|
||||
$draw,
|
||||
$start,
|
||||
$length,
|
||||
$search,
|
||||
$filters
|
||||
);
|
||||
|
||||
$rows = [];
|
||||
foreach ($result['data'] as $index => $row) {
|
||||
$rows[] = $this->formatInceptionRowForDataTable($row, $start + $index + 1);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'draw' => $result['draw'],
|
||||
'recordsTotal' => $result['recordsTotal'],
|
||||
'recordsFiltered' => $result['recordsFiltered'],
|
||||
'data' => $rows,
|
||||
'cache_expires_in_ms' => $result['cache_expires_in_ms'] ?? 300000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function clearInceptionListCache()
|
||||
{
|
||||
if (!$this->request->isAJAX()) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Invalid request.',
|
||||
]);
|
||||
}
|
||||
|
||||
session()->set('inception_list_cache_version', time());
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => true,
|
||||
'message' => 'Inception list cache cleared.',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function buildInceptionFiltersFromRequest(): array
|
||||
{
|
||||
$normalize = static function ($value) {
|
||||
return (!isset($value) || $value === '' || $value === null) ? 0 : $value;
|
||||
};
|
||||
|
||||
$ids = [];
|
||||
if ($this->request->is('post')) {
|
||||
$postIds = $this->request->getPost('ids') ?? '';
|
||||
$ids = array_filter(explode(',', (string) $postIds));
|
||||
}
|
||||
|
||||
return [
|
||||
'start_date' => $normalize($this->request->getGet('start_date') ?? $this->request->getPost('start_date')),
|
||||
'end_date' => $normalize($this->request->getGet('end_date') ?? $this->request->getPost('end_date')),
|
||||
'client_id' => $normalize($this->request->getGet('client_id') ?? $this->request->getPost('client_id')),
|
||||
'insurer_id' => $normalize($this->request->getGet('insurer_id') ?? $this->request->getPost('insurer_id')),
|
||||
'policy_type_id' => $normalize($this->request->getGet('policy_type_id') ?? $this->request->getPost('policy_type_id')),
|
||||
'date_type' => $normalize($this->request->getGet('date_type') ?? $this->request->getPost('date_type')),
|
||||
'issuer' => $normalize($this->request->getGet('issuer') ?? $this->request->getPost('issuer')),
|
||||
'status' => $normalize($this->request->getGet('status') ?? $this->request->getPost('status')),
|
||||
'ids' => $ids,
|
||||
'cache_version' => (int) (session()->get('inception_list_cache_version') ?? 1),
|
||||
];
|
||||
}
|
||||
|
||||
protected function formatInceptionRowForDataTable(array $row, int $serialNo): array
|
||||
{
|
||||
$issuerMap = [1 => 'JIBS', 2 => 'Nhance'];
|
||||
$issuingTypeMap = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over'];
|
||||
$clientTypeMap = [1 => 'Group', 2 => 'Individual'];
|
||||
$policyStatusMap = [
|
||||
'under_process' => 'Under Process',
|
||||
'client_pending' => 'Client Pending',
|
||||
'insurer_pending' => 'Insurer Pending',
|
||||
'co_insurer_pending' => 'Co-Insurer Pending',
|
||||
'tpa_pending' => 'TPA Pending',
|
||||
'validated' => 'Validated',
|
||||
'cancelled' => 'Cancelled',
|
||||
'instalment_pending' => 'Instalment Pending',
|
||||
'completed' => 'Completed',
|
||||
'lost' => 'Lost',
|
||||
];
|
||||
|
||||
$clientBranch = ((int) ($row['client_type'] ?? 0) === 2)
|
||||
? (($row['client_name'] ?? 'N/A') . ' - ' . (!empty($row['pan']) ? $row['pan'] : 'N/A'))
|
||||
: (($row['client_short_name'] ?? 'N/A') . ' - ' . ($row['client_branch_name'] ?? 'N/A'));
|
||||
|
||||
$editAction = '<a class="dropdown-item btnEdit" data-id="' . ($row['id'] ?? '') . '" onclick="alertEveryFiveSeconds(\'' . htmlspecialchars((string) ($row['id'] ?? ''), ENT_QUOTES) . '\')"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>';
|
||||
$deleteAction = '';
|
||||
if ((int) get_role_id() === 5) {
|
||||
$deleteAction = '<a class="dropdown-item delete" data-id="' . ($row['id'] ?? '') . '" onclick="removePolicyTransaction(this, \'' . htmlspecialchars((string) ($row['id'] ?? ''), ENT_QUOTES) . '\', ' . (int) ($row['policy_type_id'] ?? 0) . ')"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>';
|
||||
}
|
||||
|
||||
$actionHtml = '<div class="btn-group dropdown"><a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a><div class="dropdown-menu dropdown-menu-right">' . $editAction . $deleteAction . '</div></div>';
|
||||
|
||||
return [
|
||||
0 => $serialNo,
|
||||
1 => $issuerMap[$row['issuer'] ?? 2] ?? 'Nhance',
|
||||
2 => $issuingTypeMap[$row['issue_type'] ?? 0] ?? 'N/A',
|
||||
3 => $clientTypeMap[$row['client_type'] ?? 0] ?? 'N/A',
|
||||
4 => $clientBranch,
|
||||
5 => $row['insurer_short_name'] ?: 'N/A',
|
||||
6 => $row['policy_type'] ?: 'N/A',
|
||||
7 => $row['policy_no'] ?: 'N/A',
|
||||
8 => empty($row['policy_issue_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_issue_date'])),
|
||||
9 => empty($row['policy_start_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_start_date'])),
|
||||
10 => empty($row['policy_end_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_end_date'])),
|
||||
11 => $row['emp_count'] ?: '0',
|
||||
12 => $row['dependent_count'] ?: '0',
|
||||
13 => $policyStatusMap[$row['status'] ?? ''] ?? 'N/A',
|
||||
14 => $row['user_name'] ?: 'N/A',
|
||||
15 => $actionHtml,
|
||||
];
|
||||
}
|
||||
|
||||
public function viewInception2()
|
||||
{
|
||||
$bds_edit_pt_id = $this->request->getGet('pt_id') ?? null;
|
||||
@ -921,6 +1001,8 @@ class PolicyTransactionController extends BaseController
|
||||
// policy Transaction Create function start
|
||||
public function createInceptionPolicy()
|
||||
{
|
||||
session()->set('inception_list_cache_version', time());
|
||||
|
||||
$post_data = $this->request->getPost();
|
||||
|
||||
$rules = [
|
||||
@ -2391,31 +2473,8 @@ class PolicyTransactionController extends BaseController
|
||||
'policy_end_date' => 'Policy End Date',
|
||||
];
|
||||
|
||||
//filter datas
|
||||
$start_date = $this->request->getGet('start_date');
|
||||
$end_date = $this->request->getGet('end_date');
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$insurer_id = $this->request->getGet('insurer_id');
|
||||
$policy_type_id = $this->request->getGet('policy_type_id');
|
||||
$date_type = $this->request->getGet('date_type');
|
||||
$issuer = $this->request->getGet('issuer');
|
||||
$status = $this->request->getGet('status');
|
||||
|
||||
$start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : $start_date;
|
||||
$end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : $end_date;
|
||||
|
||||
$client_id = (!isset($client_id) || $client_id === '' || $client_id === null) ? 0 : $client_id;
|
||||
$insurer_id = (!isset($insurer_id) || $insurer_id === '' || $insurer_id === null) ? 0 : $insurer_id;
|
||||
$policy_type_id = (!isset($policy_type_id) || $policy_type_id === '' || $policy_type_id === null) ? 0 : $policy_type_id;
|
||||
$date_type = (!isset($date_type) || $date_type === '' || $date_type === null) ? 0 : $date_type;
|
||||
$issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer;
|
||||
$status = (!isset($status) || $status === '' || $status === null) ? 0 : $status;
|
||||
|
||||
if($bds_edit_pt_id == null){
|
||||
$data['endorsement_data_list'] = $this->policyTransactionModel->getEndorsementTranctionListData($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $status);
|
||||
}else{
|
||||
$data['endorsement_data_list'] = [];
|
||||
}
|
||||
$data['endorsement_data_list'] = [];
|
||||
$data['endorsement_filters'] = $this->buildEndorsementFiltersFromRequest();
|
||||
$data['client'] = $this->clientModel->where('is_active', 1)->findAll();
|
||||
$data['policy_types'] = $this->policyTypeModel->where('is_active', 1)->findAll();
|
||||
|
||||
@ -2434,6 +2493,134 @@ class PolicyTransactionController extends BaseController
|
||||
$this->loadLayout('policy_transaction_endorsement_list', $data);
|
||||
}
|
||||
|
||||
public function endorsementListDataTable()
|
||||
{
|
||||
if (!$this->request->isAJAX()) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Invalid request.',
|
||||
]);
|
||||
}
|
||||
|
||||
$draw = (int) ($this->request->getPost('draw') ?? 0);
|
||||
$start = max(0, (int) ($this->request->getPost('start') ?? 0));
|
||||
$length = (int) ($this->request->getPost('length') ?? 10);
|
||||
$search = trim((string) ($this->request->getPost('search')['value'] ?? ''));
|
||||
|
||||
$filters = $this->buildEndorsementFiltersFromRequest();
|
||||
$result = $this->policyTransactionModel->getEndorsementTranctionListDataTable(
|
||||
$draw,
|
||||
$start,
|
||||
$length,
|
||||
$search,
|
||||
$filters
|
||||
);
|
||||
|
||||
$rows = [];
|
||||
foreach ($result['data'] as $index => $row) {
|
||||
$rows[] = $this->formatEndorsementRowForDataTable($row, $start + $index + 1);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'draw' => $result['draw'],
|
||||
'recordsTotal' => $result['recordsTotal'],
|
||||
'recordsFiltered' => $result['recordsFiltered'],
|
||||
'data' => $rows,
|
||||
'cache_expires_in_ms' => $result['cache_expires_in_ms'] ?? 300000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function clearEndorsementListCache()
|
||||
{
|
||||
if (!$this->request->isAJAX()) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Invalid request.',
|
||||
]);
|
||||
}
|
||||
|
||||
session()->set('endorsement_list_cache_version', time());
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => true,
|
||||
'message' => 'Endorsement list cache cleared.',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function buildEndorsementFiltersFromRequest(): array
|
||||
{
|
||||
$normalize = static function ($value) {
|
||||
return (!isset($value) || $value === '' || $value === null) ? 0 : $value;
|
||||
};
|
||||
|
||||
return [
|
||||
'start_date' => $normalize($this->request->getGet('start_date') ?? $this->request->getPost('start_date')),
|
||||
'end_date' => $normalize($this->request->getGet('end_date') ?? $this->request->getPost('end_date')),
|
||||
'client_id' => $normalize($this->request->getGet('client_id') ?? $this->request->getPost('client_id')),
|
||||
'insurer_id' => $normalize($this->request->getGet('insurer_id') ?? $this->request->getPost('insurer_id')),
|
||||
'policy_type_id' => $normalize($this->request->getGet('policy_type_id') ?? $this->request->getPost('policy_type_id')),
|
||||
'date_type' => $normalize($this->request->getGet('date_type') ?? $this->request->getPost('date_type')),
|
||||
'issuer' => $normalize($this->request->getGet('issuer') ?? $this->request->getPost('issuer')),
|
||||
'status' => $normalize($this->request->getGet('status') ?? $this->request->getPost('status')),
|
||||
'cache_version' => (int) (session()->get('endorsement_list_cache_version') ?? 1),
|
||||
];
|
||||
}
|
||||
|
||||
protected function formatEndorsementRowForDataTable(array $row, int $serialNo): array
|
||||
{
|
||||
$issuerMap = [1 => 'JIBS', 2 => 'Nhance'];
|
||||
$policyStatusMap = [
|
||||
'under_process' => 'Under Process',
|
||||
'client_pending' => 'Client Pending',
|
||||
'insurer_pending' => 'Insurer Pending',
|
||||
'co_insurer_pending' => 'Co-Insurer Pending',
|
||||
'tpa_pending' => 'TPA Pending',
|
||||
'validated' => 'Validated',
|
||||
'cancelled' => 'Cancelled',
|
||||
'instalment_pending' => 'Instalment Pending',
|
||||
'completed' => 'Completed',
|
||||
];
|
||||
$actionTypeMap = [
|
||||
'addition' => 'Addition',
|
||||
'deletion' => 'Deletion',
|
||||
'addition_deletion' => 'Addition & Deletion',
|
||||
'si_enhancement' => 'SI Enhancement',
|
||||
'combo_a_d_si' => 'Combo A, D & SI',
|
||||
'correction' => 'Correction',
|
||||
'baby_addition' => 'Baby Addition',
|
||||
'policy_instalment' => 'Policy Instalment',
|
||||
'addition_inception' => 'Addition-Inception',
|
||||
'bds_correction' => 'BDS Correction',
|
||||
'policy_correction' => 'Policy Correction',
|
||||
'policy_cancellation' => 'Policy Cancellation',
|
||||
];
|
||||
|
||||
$editAction = '<a class="dropdown-item btnEdit" data-id="' . ($row['id'] ?? '') . '" onclick="getPolicyTransactionDataForEndorsementEdit(\'' . htmlspecialchars((string) ($row['id'] ?? ''), ENT_QUOTES) . '\')"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>';
|
||||
$deleteAction = '';
|
||||
if ((int) get_role_id() === 5) {
|
||||
$deleteAction = '<a class="dropdown-item delete" data-id="' . ($row['id'] ?? '') . '" onclick="removePolicyTransaction(this, \'' . htmlspecialchars((string) ($row['id'] ?? ''), ENT_QUOTES) . '\', ' . (int) ($row['policy_type_id'] ?? 0) . ')"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>';
|
||||
}
|
||||
|
||||
$actionHtml = '<div class="btn-group dropdown"><a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a><div class="dropdown-menu dropdown-menu-right">' . $editAction . $deleteAction . '</div></div>';
|
||||
|
||||
return [
|
||||
0 => $serialNo,
|
||||
1 => $issuerMap[$row['issuer'] ?? 0] ?? 'N/A',
|
||||
2 => $row['client_short_name'] ?: 'N/A',
|
||||
3 => $row['client_branch_name'] ?: 'N/A',
|
||||
4 => $row['insurer_short_name'] ?: 'N/A',
|
||||
5 => $row['policy_type'] ?: 'N/A',
|
||||
6 => $actionTypeMap[$row['action_type'] ?? ''] ?? 'N/A',
|
||||
7 => $row['endorsement_no'] ?: 'N/A',
|
||||
8 => empty($row['data_received_date']) ? 'N/A' : date('d/m/Y', strtotime($row['data_received_date'])),
|
||||
9 => $row['emp_count'] ?: '0',
|
||||
10 => $row['dependent_count'] ?: '0',
|
||||
11 => empty($row['policy_issue_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_issue_date'])),
|
||||
12 => $policyStatusMap[$row['status'] ?? ''] ?? 'N/A',
|
||||
13 => $actionHtml,
|
||||
];
|
||||
}
|
||||
|
||||
public function viewEndorsement2()
|
||||
{
|
||||
// echo '<pre>';
|
||||
@ -2530,6 +2717,8 @@ class PolicyTransactionController extends BaseController
|
||||
|
||||
public function createEndorsementPolicy()
|
||||
{
|
||||
session()->set('endorsement_list_cache_version', time());
|
||||
|
||||
// $id = $this->request->getPost('id');
|
||||
$rules = [
|
||||
// ==========================================
|
||||
@ -3793,65 +3982,230 @@ class PolicyTransactionController extends BaseController
|
||||
$data['users'] = $this->userModel->where('is_active', 1)->findAll();
|
||||
$data['policy_count'] = $this->policyTransactionModel->where('is_active', 1)->countAllResults();
|
||||
|
||||
|
||||
//filter datas
|
||||
$start_date = $this->request->getGet('start_date');
|
||||
$end_date = $this->request->getGet('end_date');
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$insurer_id = $this->request->getGet('insurer_id');
|
||||
$policy_type_id = $this->request->getGet('policy_type_id');
|
||||
$date_type = $this->request->getGet('date_type');
|
||||
$issuer = $this->request->getGet('issuer');
|
||||
$client_branch_id = $this->request->getGet('client_branch_id');
|
||||
$insurer_branch_id = $this->request->getGet('insurer_branch_id');
|
||||
$client_policy_id = $this->request->getGet('client_policy_id');
|
||||
$user_id = $this->request->getGet('user_id');
|
||||
|
||||
if ($date_type == 'statement_month') {
|
||||
$start_date = (string)date('Y-m-01', strtotime($start_date));
|
||||
$end_date = (string)date('Y-m-31', strtotime($end_date));
|
||||
}
|
||||
|
||||
// dd($start_date, $end_date, $date_type);
|
||||
|
||||
$start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : $start_date;
|
||||
$end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : $end_date;
|
||||
|
||||
$client_id = (!isset($client_id) || $client_id === '' || $client_id === null) ? 0 : $client_id;
|
||||
$insurer_id = (!isset($insurer_id) || $insurer_id === '' || $insurer_id === null) ? 0 : $insurer_id;
|
||||
$policy_type_id = (!isset($policy_type_id) || $policy_type_id === '' || $policy_type_id === null) ? 0 : $policy_type_id;
|
||||
$date_type = (!isset($date_type) || $date_type === '' || $date_type === null) ? 0 : $date_type;
|
||||
$issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer;
|
||||
$client_branch_id = (!isset($client_branch_id) || $client_branch_id === '' || $client_branch_id === null) ? 0 : $client_branch_id;
|
||||
$insurer_branch_id = (!isset($insurer_branch_id) || $insurer_branch_id === '' || $insurer_branch_id === null) ? 0 : $insurer_branch_id;
|
||||
$client_policy_id = (!isset($client_policy_id) || $client_policy_id === '' || $client_policy_id === null) ? 0 : $client_policy_id;
|
||||
$user_id = (!isset($user_id) || $user_id === '' || $user_id === null) ? 0 : $user_id;
|
||||
if ($this->request->is('post')) {
|
||||
$request_post_data = $this->request->getPost();
|
||||
$sanitized_post_data = sanitizeInputArrayAdvanced($request_post_data);
|
||||
$isFromDashboard = $sanitized_post_data["is_dashboard"];
|
||||
|
||||
if (isset($isFromDashboard) && !empty($isFromDashboard) && $isFromDashboard == 1) {
|
||||
$ids = $sanitized_post_data['ids'];
|
||||
|
||||
$ids = array_filter(explode(',', $ids));
|
||||
|
||||
if (!empty($ids)) {
|
||||
$idsStr = implode(',', array_map('intval', $ids)); // sanitize IDs to be integers
|
||||
$where = "policy_transaction.id IN ($idsStr)";
|
||||
} else {
|
||||
$where = []; // No valid IDs, return empty result
|
||||
}
|
||||
}
|
||||
// dd($ids);
|
||||
}
|
||||
//Actual data for the list
|
||||
$data['report_list'] = $this->policyTransactionModel->getBDSReportList($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $client_branch_id, $insurer_branch_id, $client_policy_id, $user_id, isset($where) ? $where : '');
|
||||
// List data loaded via server-side DataTables AJAX
|
||||
$data['report_list'] = [];
|
||||
$data['bds_filters'] = $this->buildBDSReportFiltersFromRequest();
|
||||
// dd($data);
|
||||
|
||||
$this->loadLayout('report_bds_filter', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Server-side DataTables endpoint for BDS report list.
|
||||
*/
|
||||
public function reportBDSDataTable()
|
||||
{
|
||||
if (!$this->request->isAJAX()) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Invalid request.',
|
||||
]);
|
||||
}
|
||||
|
||||
$draw = (int) ($this->request->getPost('draw') ?? 0);
|
||||
$start = max(0, (int) ($this->request->getPost('start') ?? 0));
|
||||
$length = (int) ($this->request->getPost('length') ?? 10);
|
||||
$search = trim((string) ($this->request->getPost('search')['value'] ?? ''));
|
||||
|
||||
$filters = $this->buildBDSReportFiltersFromRequest();
|
||||
|
||||
$result = $this->policyTransactionModel->getBDSReportListDataTable(
|
||||
$draw,
|
||||
$start,
|
||||
$length,
|
||||
$search,
|
||||
$filters
|
||||
);
|
||||
|
||||
$serialStart = $start + 1;
|
||||
$data = [];
|
||||
|
||||
foreach ($result['data'] as $index => $row) {
|
||||
$data[] = $this->formatBdsReportRowForDataTable($row, $serialStart + $index);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'draw' => $result['draw'],
|
||||
'recordsTotal' => $result['recordsTotal'],
|
||||
'recordsFiltered' => $result['recordsFiltered'],
|
||||
'data' => $data,
|
||||
'totals' => $result['totals'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function clearReportBDSCache()
|
||||
{
|
||||
if (!$this->request->isAJAX()) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Invalid request.',
|
||||
]);
|
||||
}
|
||||
|
||||
session()->set('bds_report_cache_version', time());
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => true,
|
||||
'message' => 'BDS report cache cleared.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize BDS report filter params from the current request.
|
||||
*/
|
||||
protected function buildBDSReportFiltersFromRequest(): array
|
||||
{
|
||||
$start_date = $this->request->getGet('start_date') ?? $this->request->getPost('start_date');
|
||||
$end_date = $this->request->getGet('end_date') ?? $this->request->getPost('end_date');
|
||||
$client_id = $this->request->getGet('client_id') ?? $this->request->getPost('client_id');
|
||||
$insurer_id = $this->request->getGet('insurer_id') ?? $this->request->getPost('insurer_id');
|
||||
$policy_type_id = $this->request->getGet('policy_type_id') ?? $this->request->getPost('policy_type_id');
|
||||
$date_type = $this->request->getGet('date_type') ?? $this->request->getPost('date_type');
|
||||
$issuer = $this->request->getGet('issuer') ?? $this->request->getPost('issuer');
|
||||
$client_branch_id = $this->request->getGet('client_branch_id') ?? $this->request->getPost('client_branch_id');
|
||||
$insurer_branch_id = $this->request->getGet('insurer_branch_id') ?? $this->request->getPost('insurer_branch_id');
|
||||
$client_policy_id = $this->request->getGet('client_policy_id') ?? $this->request->getPost('client_policy_id');
|
||||
$user_id = $this->request->getGet('user_id') ?? $this->request->getPost('user_id');
|
||||
|
||||
if ($date_type == 'statement_month' && $start_date && $end_date) {
|
||||
$start_date = (string) date('Y-m-01', strtotime($start_date));
|
||||
$end_date = (string) date('Y-m-31', strtotime($end_date));
|
||||
}
|
||||
|
||||
$normalize = static function ($value) {
|
||||
return (!isset($value) || $value === '' || $value === null) ? 0 : $value;
|
||||
};
|
||||
|
||||
$where = '';
|
||||
if ($this->request->is('post')) {
|
||||
$request_post_data = $this->request->getPost();
|
||||
$sanitized_post_data = sanitizeInputArrayAdvanced($request_post_data);
|
||||
$isFromDashboard = $sanitized_post_data['is_dashboard'] ?? null;
|
||||
|
||||
if (isset($isFromDashboard) && !empty($isFromDashboard) && (int) $isFromDashboard === 1) {
|
||||
$ids = array_filter(explode(',', $sanitized_post_data['ids'] ?? ''));
|
||||
|
||||
if (!empty($ids)) {
|
||||
$idsStr = implode(',', array_map('intval', $ids));
|
||||
$where = "policy_transaction.id IN ($idsStr)";
|
||||
} else {
|
||||
$where = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'start_date' => $normalize($start_date),
|
||||
'end_date' => $normalize($end_date),
|
||||
'client_id' => $normalize($client_id),
|
||||
'insurer_id' => $normalize($insurer_id),
|
||||
'policy_type_id' => $normalize($policy_type_id),
|
||||
'date_type' => $normalize($date_type),
|
||||
'issuer' => $normalize($issuer),
|
||||
'client_branch_id' => $normalize($client_branch_id),
|
||||
'insurer_branch_id' => $normalize($insurer_branch_id),
|
||||
'client_policy_id' => $normalize($client_policy_id),
|
||||
'user_id' => $normalize($user_id),
|
||||
'where' => $where,
|
||||
'cache_version' => (int) (session()->get('bds_report_cache_version') ?? 1),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a single BDS report row for DataTables output.
|
||||
*/
|
||||
protected function formatBdsReportRowForDataTable(array $row, int $serialNo): array
|
||||
{
|
||||
$hasIrda = ((float) ($row['total_irda_amt'] ?? 0)) != 0.0;
|
||||
$actionType = strtolower((string) ($row['action_type'] ?? ''));
|
||||
$editBaseUrl = $actionType === 'policy'
|
||||
? base_url('policy_tranction/inception/list')
|
||||
: base_url('policy_tranction/endorsement/list');
|
||||
$editLink = $editBaseUrl . '?pt_id=' . ($row['id'] ?? '');
|
||||
$totalIrdaAmt = $row['total_irda_amt'] ?? '0.00';
|
||||
$unbilled = isset($row['unbilled_amount']) ? number_format((float) $row['unbilled_amount'], 2, '.', '') : '0.00';
|
||||
|
||||
$fmtDate = static function ($value) {
|
||||
return empty($value) ? 'N/A' : change_date_format($value, 'Y-m-d', 'd/m/Y');
|
||||
};
|
||||
|
||||
$fmtNum = static function ($value, int $decimals = 2) {
|
||||
return number_format((float) ($value ?? 0), $decimals, '.', '');
|
||||
};
|
||||
|
||||
$na = static function ($value) {
|
||||
return ($value !== null && $value !== '') ? $value : 'N/A';
|
||||
};
|
||||
|
||||
$cells = [
|
||||
$serialNo . ' <a href="' . $editLink . '" class="mdi mdi-pencil"></a>',
|
||||
$na($row['user_name'] ?? null),
|
||||
$na($row['policy_issue_month'] ?? null),
|
||||
$na($row['revenue_type'] ?? null),
|
||||
$na($row['client_type'] ?? null),
|
||||
$na($row['client_name'] ?? null),
|
||||
$na($row['action_type'] ?? null),
|
||||
$na($row['policy_type'] ?? null),
|
||||
$na($row['bap'] ?? null),
|
||||
$na($row['vehicle_no'] ?? null),
|
||||
$na($row['policy_no'] ?? null),
|
||||
$na($row['endorsement_no'] ?? null),
|
||||
$na($row['insurer_branch_name'] ?? null),
|
||||
$fmtDate($row['endorse_eff_date'] ?? null),
|
||||
$fmtDate($row['policy_start_date'] ?? null),
|
||||
$fmtDate($row['policy_end_date'] ?? null),
|
||||
$na($row['ref'] ?? null),
|
||||
$na($row['remarks'] ?? null),
|
||||
$hasIrda ? ($row['bp_amt'] ?: '0.00') : '0.00',
|
||||
$hasIrda ? ($row['tp_or_ter'] ?: '0.00') : '0.00',
|
||||
$hasIrda ? ($row['premium_wo_gst'] ?: '0.00') : '0.00',
|
||||
$hasIrda ? ($row['total_premium'] ?: '0.00') : '0.00',
|
||||
($hasIrda ? ($row['agreed_bp_per'] ?: '0.00') : '0.00') . '%',
|
||||
($hasIrda ? ($row['agreed_tp_or_ter_per'] ?: '0.00') : '0.00') . '%',
|
||||
isset($row['reward']) ? $row['reward'] : '0.00',
|
||||
'<span class="right-align-input" onclick="showCoShareStatementDetails(this)" data-id="' . ($row['pt_id'] ?? '') . '">' . $totalIrdaAmt . '</span>',
|
||||
'<span class="right-align-input">' . (empty($row['billed_amt']) ? '0.00' : $row['billed_amt']) . '</span>',
|
||||
'<span class="right-align-input">' . $unbilled . '</span>',
|
||||
$na($row['salse_person_name'] ?? null),
|
||||
$na($row['service_person_name'] ?? null),
|
||||
$na($row['nhance_branch'] ?? null),
|
||||
$na($row['installment'] ?? null),
|
||||
$fmtDate($row['data_received_date'] ?? null),
|
||||
$fmtDate($row['renewal_date'] ?? null),
|
||||
$row['co_share'] ?? 'No',
|
||||
$row['bro_payable_by'] ?? 'No',
|
||||
$na($row['salse_manager_name'] ?? null),
|
||||
$na($row['service_manager_name'] ?? null),
|
||||
$na($row['service_branch'] ?? null),
|
||||
$fmtDate($row['rollover_date'] ?? null),
|
||||
$na($row['policy_holder_name'] ?? null),
|
||||
$row['same_as_proposer'] ?? 'No',
|
||||
$na($row['follower_policy_no'] ?? null),
|
||||
$fmtNum($row['co_share_per'] ?? 0),
|
||||
$fmtNum($row['non_comm_per_amt'] ?? 0),
|
||||
$fmtNum($row['bp_igst'] ?? 0),
|
||||
$fmtNum($row['bp_sgst'] ?? 0),
|
||||
$fmtNum($row['bp_cgst'] ?? 0),
|
||||
$fmtNum($row['stamp_duty'] ?? 0),
|
||||
$fmtNum($row['standerd_bp_per'] ?? 0),
|
||||
$fmtNum($row['standerd_tp_per'] ?? 0),
|
||||
$fmtNum($row['actual_bp_amt'] ?? 0),
|
||||
$fmtNum($row['actual_tp_amt'] ?? 0),
|
||||
$fmtNum($row['actual_bp_per'] ?? 0),
|
||||
$fmtNum($row['actual_tp_per'] ?? 0),
|
||||
$fmtNum($row['actual_tep_brokerage_amt'] ?? 0),
|
||||
$fmtNum($row['actual_tp_brokerage_amt'] ?? 0),
|
||||
$na($row['cd_ac_no'] ?? null),
|
||||
];
|
||||
|
||||
$rowData = ['DT_RowAttr' => ['data-id' => $row['pt_id'] ?? '']];
|
||||
foreach ($cells as $index => $cell) {
|
||||
$rowData[$index] = $cell;
|
||||
}
|
||||
|
||||
return $rowData;
|
||||
}
|
||||
|
||||
public function reportVarience()
|
||||
{
|
||||
$data['tab_name'] = 'Variance Report';
|
||||
|
||||
@ -1136,6 +1136,136 @@
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getCachedInceptionTranctionListData(array $filters): array
|
||||
{
|
||||
$cacheKey = 'inception_list_v1_' . md5(json_encode($filters));
|
||||
$cache = \Config\Services::cache();
|
||||
$cached = $cache->get($cacheKey);
|
||||
|
||||
if (is_array($cached) && isset($cached['rows'], $cached['expires_at'])) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$ttl = 300;
|
||||
$rows = $this->getInceptionTranctionListData(
|
||||
$filters['start_date'] ?? 0,
|
||||
$filters['end_date'] ?? 0,
|
||||
$filters['client_id'] ?? 0,
|
||||
$filters['insurer_id'] ?? 0,
|
||||
$filters['policy_type_id'] ?? 0,
|
||||
$filters['date_type'] ?? 0,
|
||||
$filters['issuer'] ?? 0,
|
||||
$filters['status'] ?? 0,
|
||||
$filters['ids'] ?? null
|
||||
);
|
||||
|
||||
$payload = [
|
||||
'rows' => $rows,
|
||||
'expires_at' => time() + $ttl,
|
||||
];
|
||||
$cache->save($cacheKey, $payload, $ttl);
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
public function filterInceptionTranctionRowsBySearch(array $rows, string $searchValue): array
|
||||
{
|
||||
$needle = mb_strtolower(trim($searchValue));
|
||||
if ($needle === '') {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$issuerMap = [1 => 'jibs', 2 => 'nhance'];
|
||||
$issueTypeMap = [1 => 'fresh', 2 => 'renewal', 3 => 'roll over'];
|
||||
$clientTypeMap = [1 => 'group', 2 => 'individual'];
|
||||
$statusMap = [
|
||||
'under_process' => 'under process',
|
||||
'client_pending' => 'client pending',
|
||||
'insurer_pending' => 'insurer pending',
|
||||
'co_insurer_pending' => 'co-insurer pending',
|
||||
'tpa_pending' => 'tpa pending',
|
||||
'validated' => 'validated',
|
||||
'cancelled' => 'cancelled',
|
||||
'instalment_pending' => 'instalment pending',
|
||||
'completed' => 'completed',
|
||||
'lost' => 'lost',
|
||||
];
|
||||
|
||||
$fields = [
|
||||
'client_name',
|
||||
'client_short_name',
|
||||
'client_branch_name',
|
||||
'insurer_short_name',
|
||||
'policy_type',
|
||||
'policy_no',
|
||||
'user_name',
|
||||
'status',
|
||||
'pan',
|
||||
];
|
||||
|
||||
return array_values(array_filter($rows, static function (array $row) use ($needle, $fields, $issuerMap, $issueTypeMap, $clientTypeMap, $statusMap) {
|
||||
foreach ($fields as $field) {
|
||||
$value = $row[$field] ?? '';
|
||||
if ($value !== '' && mb_strpos(mb_strtolower((string) $value), $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Search by rendered labels shown in list columns.
|
||||
$issuerText = $issuerMap[(int) ($row['issuer'] ?? 0)] ?? '';
|
||||
if ($issuerText !== '' && mb_strpos($issuerText, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$issueTypeText = $issueTypeMap[(int) ($row['issue_type'] ?? 0)] ?? '';
|
||||
if ($issueTypeText !== '' && mb_strpos($issueTypeText, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$clientTypeText = $clientTypeMap[(int) ($row['client_type'] ?? 0)] ?? '';
|
||||
if ($clientTypeText !== '' && mb_strpos($clientTypeText, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$statusCode = (string) ($row['status'] ?? '');
|
||||
$statusText = $statusMap[$statusCode] ?? '';
|
||||
if ($statusText !== '' && mb_strpos($statusText, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
|
||||
public function getInceptionTranctionListDataTable(int $draw, int $start, int $length, string $searchValue, array $filters): array
|
||||
{
|
||||
$cached = $this->getCachedInceptionTranctionListData($filters);
|
||||
$allRows = $cached['rows'] ?? [];
|
||||
$recordsTotal = count($allRows);
|
||||
|
||||
if ($searchValue !== '') {
|
||||
$allRows = $this->filterInceptionTranctionRowsBySearch($allRows, $searchValue);
|
||||
}
|
||||
|
||||
$recordsFiltered = count($allRows);
|
||||
|
||||
if ($length < 0) {
|
||||
$length = $recordsFiltered;
|
||||
}
|
||||
|
||||
$pageRows = $length > 0
|
||||
? array_slice(array_values($allRows), $start, $length)
|
||||
: array_values($allRows);
|
||||
|
||||
return [
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $recordsTotal,
|
||||
'recordsFiltered' => $recordsFiltered,
|
||||
'data' => $pageRows,
|
||||
'cache_expires_in_ms' => max(0, (($cached['expires_at'] ?? time()) - time()) * 1000),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getEndorsementTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
|
||||
{
|
||||
@ -1248,6 +1378,136 @@
|
||||
return $builder->get()->getResultArray();
|
||||
}
|
||||
|
||||
public function getCachedEndorsementTranctionListData(array $filters): array
|
||||
{
|
||||
$cacheKey = 'endorsement_list_v1_' . md5(json_encode($filters));
|
||||
$cache = \Config\Services::cache();
|
||||
$cached = $cache->get($cacheKey);
|
||||
|
||||
if (is_array($cached) && isset($cached['rows'], $cached['expires_at'])) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$ttl = 300;
|
||||
$rows = $this->getEndorsementTranctionListData(
|
||||
$filters['start_date'] ?? 0,
|
||||
$filters['end_date'] ?? 0,
|
||||
$filters['client_id'] ?? 0,
|
||||
$filters['insurer_id'] ?? 0,
|
||||
$filters['policy_type_id'] ?? 0,
|
||||
$filters['date_type'] ?? 0,
|
||||
$filters['issuer'] ?? 0,
|
||||
$filters['status'] ?? 0
|
||||
);
|
||||
|
||||
$payload = [
|
||||
'rows' => $rows,
|
||||
'expires_at' => time() + $ttl,
|
||||
];
|
||||
$cache->save($cacheKey, $payload, $ttl);
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
public function filterEndorsementTranctionRowsBySearch(array $rows, string $searchValue): array
|
||||
{
|
||||
$needle = mb_strtolower(trim($searchValue));
|
||||
if ($needle === '') {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$issuerMap = [1 => 'jibs', 2 => 'nhance'];
|
||||
$statusMap = [
|
||||
'under_process' => 'under process',
|
||||
'client_pending' => 'client pending',
|
||||
'insurer_pending' => 'insurer pending',
|
||||
'co_insurer_pending' => 'co-insurer pending',
|
||||
'tpa_pending' => 'tpa pending',
|
||||
'validated' => 'validated',
|
||||
'cancelled' => 'cancelled',
|
||||
'instalment_pending' => 'instalment pending',
|
||||
'completed' => 'completed',
|
||||
];
|
||||
$actionTypeMap = [
|
||||
'addition' => 'addition',
|
||||
'deletion' => 'deletion',
|
||||
'addition_deletion' => 'addition & deletion',
|
||||
'si_enhancement' => 'si enhancement',
|
||||
'combo_a_d_si' => 'combo a, d & si',
|
||||
'correction' => 'correction',
|
||||
'baby_addition' => 'baby addition',
|
||||
'policy_instalment' => 'policy instalment',
|
||||
'addition_inception' => 'addition-inception',
|
||||
'bds_correction' => 'bds correction',
|
||||
'policy_correction' => 'policy correction',
|
||||
'policy_cancellation' => 'policy cancellation',
|
||||
];
|
||||
|
||||
$fields = [
|
||||
'client_short_name',
|
||||
'client_branch_name',
|
||||
'insurer_short_name',
|
||||
'policy_type',
|
||||
'endorsement_no',
|
||||
'policy_no',
|
||||
];
|
||||
|
||||
return array_values(array_filter($rows, static function (array $row) use ($needle, $fields, $issuerMap, $statusMap, $actionTypeMap) {
|
||||
foreach ($fields as $field) {
|
||||
$value = $row[$field] ?? '';
|
||||
if ($value !== '' && mb_strpos(mb_strtolower((string) $value), $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$issuerText = $issuerMap[(int) ($row['issuer'] ?? 0)] ?? '';
|
||||
if ($issuerText !== '' && mb_strpos($issuerText, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$statusText = $statusMap[(string) ($row['status'] ?? '')] ?? '';
|
||||
if ($statusText !== '' && mb_strpos($statusText, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$actionTypeText = $actionTypeMap[(string) ($row['action_type'] ?? '')] ?? '';
|
||||
if ($actionTypeText !== '' && mb_strpos($actionTypeText, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
|
||||
public function getEndorsementTranctionListDataTable(int $draw, int $start, int $length, string $searchValue, array $filters): array
|
||||
{
|
||||
$cached = $this->getCachedEndorsementTranctionListData($filters);
|
||||
$allRows = $cached['rows'] ?? [];
|
||||
$recordsTotal = count($allRows);
|
||||
|
||||
if ($searchValue !== '') {
|
||||
$allRows = $this->filterEndorsementTranctionRowsBySearch($allRows, $searchValue);
|
||||
}
|
||||
|
||||
$recordsFiltered = count($allRows);
|
||||
|
||||
if ($length < 0) {
|
||||
$length = $recordsFiltered;
|
||||
}
|
||||
|
||||
$pageRows = $length > 0
|
||||
? array_slice(array_values($allRows), $start, $length)
|
||||
: array_values($allRows);
|
||||
|
||||
return [
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $recordsTotal,
|
||||
'recordsFiltered' => $recordsFiltered,
|
||||
'data' => $pageRows,
|
||||
'cache_expires_in_ms' => max(0, (($cached['expires_at'] ?? time()) - time()) * 1000),
|
||||
];
|
||||
}
|
||||
|
||||
public function getVarienceReportLIst($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $client_branch_id = 0, $insurer_branch_id = 0, $client_policy_id = 0)
|
||||
{
|
||||
$builder = $this->db->table('policy_transaction')
|
||||
@ -3099,11 +3359,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Dynamic $where array
|
||||
// 2. Dynamic $where (string SQL fragment or column => value map)
|
||||
if (!empty($where)) {
|
||||
foreach ($where as $column => $value) {
|
||||
$value = addslashes($value);
|
||||
$conditions .= " AND `$column` = '$value' ";
|
||||
if (is_string($where)) {
|
||||
$conditions .= ' AND ' . $where . ' ';
|
||||
} else {
|
||||
foreach ($where as $column => $value) {
|
||||
$value = addslashes($value);
|
||||
$conditions .= " AND `$column` = '$value' ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3739,119 +4003,245 @@
|
||||
$query = $this->db->query($sql);
|
||||
$result = $query->getResultArray();
|
||||
|
||||
return $this->processBDSReportResults($result);
|
||||
}
|
||||
|
||||
// $countofalldata = count($result);
|
||||
// Kint::dump($result);
|
||||
// dd($this->db->getLastQuery()->getQuery());
|
||||
|
||||
/**
|
||||
* Post-process raw BDS report rows (dedup, rewards, unbilled amounts).
|
||||
*/
|
||||
public function processBDSReportResults(array $result): array
|
||||
{
|
||||
$keys = [];
|
||||
$filtered = [];
|
||||
|
||||
foreach ($result as $row) {
|
||||
|
||||
// Normalize endorsement number
|
||||
$endorsement_number = !empty($row['endorsement_no']) ? $row['endorsement_no'] : '-';
|
||||
|
||||
$reward = (float) ($row['reward'] ?? 0);
|
||||
$billed_amt = (float) ($row['billed_amt'] ?? 0);
|
||||
|
||||
if($reward == 0.00 && $billed_amt == 0.00 && $row['statement_uploaded'] === 'statement uploaded'){
|
||||
if ($reward == 0.00 && $billed_amt == 0.00 && $row['statement_uploaded'] === 'statement uploaded') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($reward > 0 && ($row['billed_amt'] ?? 0) == 0.00) {
|
||||
$row['total_irda_amt'] = '0.00';
|
||||
$row['billed_amt'] = $reward;
|
||||
$rewardFlag = 'R'; // Reward row
|
||||
} else {
|
||||
$rewardFlag = 'N'; // Normal row
|
||||
if ($reward > 0 && ($row['billed_amt'] ?? 0) == 0.00) {
|
||||
$row['total_irda_amt'] = '0.00';
|
||||
$row['billed_amt'] = $reward;
|
||||
$rewardFlag = 'R';
|
||||
} else {
|
||||
$rewardFlag = 'N';
|
||||
}
|
||||
|
||||
// ✅ Stable key (NO reward flag)
|
||||
$key = implode('|', [
|
||||
$row['statement_year_month'],
|
||||
$row['insurer_name'],
|
||||
$row['policy_no'],
|
||||
$endorsement_number,
|
||||
$rewardFlag
|
||||
$rewardFlag,
|
||||
]);
|
||||
|
||||
// Prefer "statement uploaded"
|
||||
if ($row['statement_uploaded'] === 'statement uploaded') {
|
||||
$filtered[$key] = $row;
|
||||
$keys[$key] = true;
|
||||
}
|
||||
// Keep no-statement only if uploaded not present
|
||||
elseif (!isset($keys[$key])) {
|
||||
$keys[$key] = true;
|
||||
} elseif (!isset($keys[$key])) {
|
||||
$filtered[$key] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// Reindex final output
|
||||
$result = array_values($filtered);
|
||||
|
||||
// dd($result);
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------
|
||||
|
||||
$totalBilled = [];
|
||||
$totalIrdaMap = [];
|
||||
|
||||
foreach ($result as $row) {
|
||||
$key = $row['pt_id'].'-'.$row['insurer_id'];
|
||||
$key = $row['pt_id'] . '-' . $row['insurer_id'];
|
||||
|
||||
// Sum billed amount
|
||||
$totalBilled[$key] = ($totalBilled[$key] ?? 0) + (float) ($row['billed_amt'] ?? 0);
|
||||
|
||||
// Store total_irda_amt once
|
||||
if (!isset($totalIrdaMap[$key])) {
|
||||
$totalIrdaMap[$key] = (float) $row['total_irda_amt'];
|
||||
}
|
||||
|
||||
if(($row['reward'] ?? 0) > 0){
|
||||
$totalIrdaMap[$key] = ($totalIrdaMap[$key] ?? 0) + (float) $row['reward'];
|
||||
if (($row['reward'] ?? 0) > 0) {
|
||||
$totalIrdaMap[$key] = ($totalIrdaMap[$key] ?? 0) + (float) $row['reward'];
|
||||
}
|
||||
}
|
||||
|
||||
// dd($totalBilled, $totalIrdaMap);
|
||||
|
||||
$ptSeen = [];
|
||||
$final = [];
|
||||
|
||||
foreach ($result as $row) {
|
||||
$ptId = $row['pt_id'].'-'.$row['insurer_id'];
|
||||
$ptId = $row['pt_id'] . '-' . $row['insurer_id'];
|
||||
if (!isset($ptSeen[$ptId])) {
|
||||
|
||||
$totalIrdaVal = $totalIrdaMap[$ptId] ?? 0;
|
||||
$totalIrdaVal = $totalIrdaMap[$ptId] ?? 0;
|
||||
$totalBilledVal = $totalBilled[$ptId] ?? 0;
|
||||
$addMinus = false;
|
||||
$addMinus = false;
|
||||
|
||||
if($totalIrdaVal < 0){
|
||||
$totalIrdaVal = abs($totalIrdaVal);
|
||||
if ($totalIrdaVal < 0) {
|
||||
$totalIrdaVal = abs($totalIrdaVal);
|
||||
$totalBilledVal = abs($totalBilledVal);
|
||||
$addMinus = true;
|
||||
$addMinus = true;
|
||||
}
|
||||
|
||||
// First entry → set unbilled amount
|
||||
$row['unbilled_amount'] = round((float) ($totalIrdaVal - $totalBilledVal),2 );
|
||||
$row['unbilled_amount'] = round((float) ($totalIrdaVal - $totalBilledVal), 2);
|
||||
|
||||
if($addMinus){
|
||||
if ($addMinus) {
|
||||
$row['unbilled_amount'] = ($row['unbilled_amount'] * -1);
|
||||
}
|
||||
|
||||
$ptSeen[$ptId] = true;
|
||||
} else {
|
||||
// Other entries → zero
|
||||
$row['unbilled_amount'] = '0.00';
|
||||
}
|
||||
|
||||
$final[] = $row;
|
||||
}
|
||||
|
||||
$result = $final;
|
||||
return $final;
|
||||
}
|
||||
|
||||
// dd($result); die;
|
||||
return $result;
|
||||
/**
|
||||
* Cached processed BDS report list for a given filter set.
|
||||
*/
|
||||
public function getCachedBDSReportList(array $filters): array
|
||||
{
|
||||
$cacheKey = 'bds_report_v1_' . md5(json_encode($filters));
|
||||
$cache = \Config\Services::cache();
|
||||
$cached = $cache->get($cacheKey);
|
||||
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$processed = $this->getBDSReportList(
|
||||
$filters['start_date'] ?? 0,
|
||||
$filters['end_date'] ?? 0,
|
||||
$filters['client_id'] ?? 0,
|
||||
$filters['insurer_id'] ?? 0,
|
||||
$filters['policy_type_id'] ?? 0,
|
||||
$filters['date_type'] ?? 0,
|
||||
$filters['issuer'] ?? 0,
|
||||
$filters['client_branch_id'] ?? 0,
|
||||
$filters['insurer_branch_id'] ?? 0,
|
||||
$filters['client_policy_id'] ?? 0,
|
||||
$filters['user_id'] ?? 0,
|
||||
$filters['where'] ?? []
|
||||
);
|
||||
|
||||
$cache->save($cacheKey, $processed, 300);
|
||||
|
||||
return $processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Server-side DataTables payload for BDS report.
|
||||
*/
|
||||
public function getBDSReportListDataTable(int $draw, int $start, int $length, string $searchValue, array $filters): array
|
||||
{
|
||||
$allRows = $this->getCachedBDSReportList($filters);
|
||||
$recordsTotal = count($allRows);
|
||||
|
||||
if ($searchValue !== '') {
|
||||
$allRows = $this->filterBDSReportRowsBySearch($allRows, $searchValue);
|
||||
}
|
||||
|
||||
$recordsFiltered = count($allRows);
|
||||
|
||||
if ($length < 0) {
|
||||
$length = $recordsFiltered;
|
||||
}
|
||||
|
||||
$pageRows = $length > 0
|
||||
? array_slice(array_values($allRows), $start, $length)
|
||||
: array_values($allRows);
|
||||
|
||||
return [
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $recordsTotal,
|
||||
'recordsFiltered' => $recordsFiltered,
|
||||
'data' => $pageRows,
|
||||
'totals' => $this->calculateBDSReportTotals($allRows),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Global search across BDS report row fields.
|
||||
*/
|
||||
public function filterBDSReportRowsBySearch(array $rows, string $searchValue): array
|
||||
{
|
||||
$needle = mb_strtolower(trim($searchValue));
|
||||
if ($needle === '') {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// Match DataTables "common search" behavior against primary visible columns.
|
||||
$searchFields = [
|
||||
'user_name',
|
||||
'policy_issue_month',
|
||||
'client_name',
|
||||
'action_type',
|
||||
'policy_type',
|
||||
'policy_no',
|
||||
'endorsement_no',
|
||||
'insurer_branch_name',
|
||||
];
|
||||
|
||||
return array_values(array_filter($rows, static function (array $row) use ($needle, $searchFields) {
|
||||
foreach ($searchFields as $field) {
|
||||
$value = $row[$field] ?? '';
|
||||
if ($value !== '' && mb_strpos(mb_strtolower((string) $value), $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$numericFields = [
|
||||
'bp_amt', 'tp_or_ter', 'premium_wo_gst', 'total_premium', 'agreed_bp_per',
|
||||
'agreed_tp_or_ter_per', 'reward', 'total_irda_amt', 'billed_amt', 'unbilled_amount',
|
||||
];
|
||||
foreach ($numericFields as $field) {
|
||||
$value = $row[$field] ?? '';
|
||||
if ($value !== '' && $value !== null && mb_strpos((string) $value, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary totals for BDS report badges (matches client-side footerCallback logic).
|
||||
*/
|
||||
public function calculateBDSReportTotals(array $rows): array
|
||||
{
|
||||
$totalPremium = 0.0;
|
||||
$totalRewards = 0.0;
|
||||
$totalIrda = 0.0;
|
||||
$totalBilled = 0.0;
|
||||
$totalUnbilled = 0.0;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$hasIrda = ((float) ($row['total_irda_amt'] ?? 0)) != 0.0;
|
||||
|
||||
$totalPremium += $hasIrda ? (float) ($row['premium_wo_gst'] ?? 0) : 0.0;
|
||||
$totalRewards += (float) ($row['reward'] ?? 0);
|
||||
$totalIrda += (float) ($row['total_irda_amt'] ?? 0);
|
||||
$totalBilled += (float) ($row['billed_amt'] ?? 0);
|
||||
$totalUnbilled += (float) ($row['unbilled_amount'] ?? 0);
|
||||
}
|
||||
|
||||
$totalIrdaAmt = $totalBilled - $totalRewards;
|
||||
$totalRevenue = $totalIrdaAmt + $totalRewards;
|
||||
|
||||
return [
|
||||
'total_premium' => number_format($totalPremium, 2, '.', ''),
|
||||
'total_rewards' => number_format($totalRewards, 2, '.', ''),
|
||||
'total_irda' => number_format($totalIrdaAmt, 2, '.', ''),
|
||||
'total_revenue' => number_format($totalRevenue, 2, '.', ''),
|
||||
'total_billed' => number_format($totalBilled, 2, '.', ''),
|
||||
'total_unbilled' => number_format($totalUnbilled, 2, '.', ''),
|
||||
'policy_count' => count($rows),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -293,40 +293,7 @@
|
||||
<th class="font-weight-medium text-center">Action </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($endorsement_data_list as $index => $row) { ?>
|
||||
<tr>
|
||||
<td><?php echo $index + 1; ?></td>
|
||||
<td><?php echo $issuer[$row['issuer']] ?? 'N/A'; ?></td><!-- Issuer -->
|
||||
<td><?php echo $row['client_short_name'] ?: 'N/A'; ?></td><!-- Client -->
|
||||
<td><?php echo $row['client_branch_name'] ?: 'N/A'; ?></td><!-- Branch -->
|
||||
<td><?php echo $row['insurer_short_name'] ?: 'N/A'; ?></td><!-- Insurer -->
|
||||
<td><?php echo $row['policy_type'] ?: 'N/A'; ?></td><!-- Policy -->
|
||||
<td><?php echo $action_type[$row['action_type']] ?: 'N/A';?></td>
|
||||
<td><?php echo $row['endorsement_no'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo empty($row['data_received_date']) ? 'N/A' : date('d/m/Y', strtotime($row['data_received_date'])); ?></td>
|
||||
<td class="right-align-input"><?php echo $row['emp_count'] ?: '0'; ?></td>
|
||||
<td class="right-align-input"><?php echo $row['dependent_count'] ?: '0'; ?></td>
|
||||
<td><?php echo empty($row['policy_issue_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_issue_date'])); ?></td>
|
||||
<td><?php echo $policy_status[$row['status']] ?: 'N/A'; ?></td>
|
||||
<td class="text-center table-action-cell">
|
||||
<div class="btn-group dropdown">
|
||||
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<a class="dropdown-item btnEdit" data-id="<?= $row['id']; ?>" onclick="getPolicyTransactionDataForEndorsementEdit('<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>')">
|
||||
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
|
||||
</a>
|
||||
<?php if(get_role_id() == 5): ?>
|
||||
<a class="dropdown-item delete" data-id="<?= $row['id'];?>" onclick="removePolicyTransaction(this, '<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>', <?= $row['policy_type_id'] ?>)">
|
||||
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
<tbody></tbody>
|
||||
</table><!-- table -->
|
||||
</div><!-- card-body -->
|
||||
</div><!-- card -->
|
||||
@ -388,32 +355,122 @@
|
||||
|
||||
})
|
||||
|
||||
var endorsementTableFilters = <?= json_encode($endorsement_filters ?? []) ?>;
|
||||
var endorsementListDataTableUrl = '<?= base_url('policy_tranction/endorsement/list/datatable') ?>';
|
||||
var endorsementClearCacheUrl = '<?= base_url('policy_tranction/endorsement/list/clear-cache') ?>';
|
||||
var endorsementAutoReloadTimer = null;
|
||||
|
||||
function scheduleEndorsementAutoReload(ms) {
|
||||
if (endorsementAutoReloadTimer) {
|
||||
clearTimeout(endorsementAutoReloadTimer);
|
||||
}
|
||||
if (ms > 0) {
|
||||
endorsementAutoReloadTimer = setTimeout(function() {
|
||||
window.location.reload();
|
||||
}, ms);
|
||||
}
|
||||
}
|
||||
|
||||
function exportServerSideFilteredEndorsementData(e, dt, button, config, buttonType) {
|
||||
var self = this;
|
||||
var oldStart = dt.page.info().start;
|
||||
|
||||
dt.one('preXhr', function (x, s, data) {
|
||||
data.start = 0;
|
||||
data.length = -1;
|
||||
});
|
||||
|
||||
dt.one('draw', function () {
|
||||
$.fn.dataTable.ext.buttons[buttonType].action.call(self, e, dt, button, config);
|
||||
|
||||
dt.one('preXhr', function (x, s, data) {
|
||||
data.start = oldStart;
|
||||
data.length = dt.page.len();
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
dt.ajax.reload(null, false);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
dt.ajax.reload();
|
||||
}
|
||||
|
||||
function clearEndorsementCacheAndReloadTable(dt) {
|
||||
$.ajax({
|
||||
url: endorsementClearCacheUrl,
|
||||
type: 'POST',
|
||||
success: function(response) {
|
||||
if (response && response.status) {
|
||||
endorsementTableFilters.cache_version = new Date().getTime();
|
||||
dt.ajax.reload(null, true);
|
||||
toastr.success(response.message || 'Cache cleared and list reloaded.', 'Success');
|
||||
} else {
|
||||
toastr.warning((response && response.message) ? response.message : 'Unable to clear cache.', 'Warning');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
toastr.error('Failed to clear cache.', 'Error');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//DataTable document ready
|
||||
$(document).ready(function() {
|
||||
var ticketsTable = $('#tickets-table');
|
||||
|
||||
if (ticketsTable.length) {
|
||||
var table = ticketsTable.DataTable({
|
||||
scrollX: true,
|
||||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||||
"<'row'<'col-sm-12'tr>>" +
|
||||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||||
buttons: [
|
||||
nhanceListDataTableBeforeInit();
|
||||
var table = ticketsTable.DataTable(nhanceMergeListDataTableOptions({
|
||||
autoWidth: false,
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
deferRender: true,
|
||||
searchDelay: 400,
|
||||
columns: (function() {
|
||||
var cols = [];
|
||||
for (var i = 0; i < 14; i++) {
|
||||
cols.push({ data: String(i), orderable: false });
|
||||
}
|
||||
return cols;
|
||||
})(),
|
||||
ajax: {
|
||||
url: endorsementListDataTableUrl,
|
||||
type: 'POST',
|
||||
data: function(d) {
|
||||
return $.extend({}, d, endorsementTableFilters);
|
||||
},
|
||||
dataSrc: function(json) {
|
||||
scheduleEndorsementAutoReload(json.cache_expires_in_ms || 300000);
|
||||
return json.data;
|
||||
}
|
||||
},
|
||||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" +
|
||||
"<'row'<'col-sm-12'tr>>" +
|
||||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="mdi mdi-refresh" ></i><span class=" btn-custom"> Reload </span>',
|
||||
className: 'btn app-btn-secondary mr-2',
|
||||
action: function(e, dt) {
|
||||
clearEndorsementCacheAndReloadTable(dt);
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '<i class="mdi mdi-filter"></i><span class="btn-custom"> Filter </span>',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
action: function (e, dt, node, config) {
|
||||
action: function () {
|
||||
openEndorsementFilterNav();
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
text: '<i class="mdi mdi-plus" ></i><span class=" btn-custom"> Add </span>',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
action: function (e, dt, node, config) {
|
||||
action: function () {
|
||||
hide_list_show_add();
|
||||
addHTMLInput(null, 'policy_docs_div');
|
||||
$('#policy_docs').show()
|
||||
$('#policy_docs').show();
|
||||
},
|
||||
attr: { id: 'btnAdd' }
|
||||
},
|
||||
@ -422,14 +479,30 @@
|
||||
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
|
||||
className: 'btn app-btn-secondary ',
|
||||
buttons: [
|
||||
{
|
||||
extend: 'csv',
|
||||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||
title: 'Policy-Tranction-Endorsement-List',
|
||||
exportOptions: {
|
||||
columns: ':not(:last-child)'
|
||||
},
|
||||
}
|
||||
{
|
||||
extend: 'csv',
|
||||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||
title: 'Policy-Tranction-Endorsement-List',
|
||||
action: function (e, dt, button, config) {
|
||||
exportServerSideFilteredEndorsementData.call(this, e, dt, button, config, 'csvHtml5');
|
||||
},
|
||||
exportOptions: {
|
||||
modifier: { search: 'applied', page: 'all' },
|
||||
columns: ':not(:last-child)'
|
||||
},
|
||||
},
|
||||
{
|
||||
extend: 'excel',
|
||||
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
|
||||
title: 'Policy-Tranction-Endorsement-List',
|
||||
action: function (e, dt, button, config) {
|
||||
exportServerSideFilteredEndorsementData.call(this, e, dt, button, config, 'excelHtml5');
|
||||
},
|
||||
exportOptions: {
|
||||
modifier: { search: 'applied', page: 'all' },
|
||||
columns: ':not(:last-child)'
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -444,33 +517,14 @@
|
||||
</div>`,
|
||||
searchPlaceholder: "Search",
|
||||
emptyTable: '<div class="text-center text-muted">No Data found</div>',
|
||||
paginate: {
|
||||
previous: '◄',
|
||||
next: '►'
|
||||
}
|
||||
paginate: { previous: '◄', next: '►' }
|
||||
},
|
||||
paging: true, // Enable pagination
|
||||
pageLength: 10, // Set default number of rows per page (optional)
|
||||
paging: true,
|
||||
pageLength: 10,
|
||||
ordering: false,
|
||||
});
|
||||
|
||||
function applyBottomRowDropup() {
|
||||
if (!table) return;
|
||||
|
||||
const currentRows = table.rows({ page: 'current' }).nodes().toArray();
|
||||
$('#tickets-table tbody tr').removeClass('nh-force-dropup');
|
||||
$('#tickets-table tbody tr td.table-action-cell .btn-group.dropdown').removeClass('dropup');
|
||||
|
||||
const targetCount = Math.min(2, currentRows.length);
|
||||
for (let i = 0; i < targetCount; i++) {
|
||||
const row = currentRows[currentRows.length - 1 - i];
|
||||
if (!row) continue;
|
||||
$(row).addClass('nh-force-dropup');
|
||||
$(row).find('td.table-action-cell .btn-group.dropdown').addClass('dropup');
|
||||
}
|
||||
}
|
||||
applyBottomRowDropup();
|
||||
ticketsTable.on('draw.dt', applyBottomRowDropup);
|
||||
}));
|
||||
nhanceListDataTableAfterInit();
|
||||
nhanceListDataTableBindAdjust(table);
|
||||
} else {
|
||||
console.error("Table not found.");
|
||||
}
|
||||
|
||||
@ -321,43 +321,7 @@ table.dataTable tbody td {
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<?php foreach($inception_data_list as $index => $row){ ?>
|
||||
<tr>
|
||||
<td class="text-center"><?php echo $index+1; ?></td>
|
||||
<td><?php echo $issuer[$row['issuer']] ?? 'Nhance'; ?></td>
|
||||
<td><?php echo $issuing_type[$row['issue_type']] ?? 'N/A'; ?></td>
|
||||
<td><?php echo $client_type[$row['client_type']] ?? 'N/A'; ?></td>
|
||||
<td><?php echo $row['client_type'] == 2 ? $row['client_name'] . " - " . (!empty($row['pan']) ? $row['pan'] : 'N/A') : $row['client_short_name'] . ' - ' . $row['client_branch_name']; ?></td>
|
||||
<td><?php echo $row['insurer_short_name'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['policy_type'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['policy_no'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo empty($row['policy_issue_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_issue_date'])); ?></td>
|
||||
<td><?php echo empty($row['policy_issue_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_start_date'])); ?></td>
|
||||
<td><?php echo empty($row['policy_issue_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_end_date'])); ?></td>
|
||||
<td class="right-align-input"><?php echo $row['emp_count'] ?: '0'; ?></td>
|
||||
<td class="right-align-input"><?php echo $row['dependent_count'] ?: '0'; ?></td>
|
||||
<td><?php echo $policy_status[$row['status']] ?? 'N/A'; ?></td>
|
||||
<td><?php echo $row['user_name'] ?: 'N/A'; ?></td>
|
||||
<td>
|
||||
<div class="btn-group dropdown">
|
||||
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<a class="dropdown-item btnEdit" data-id="<?= $row['id'];?>" onclick="alertEveryFiveSeconds('<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>')">
|
||||
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
|
||||
</a>
|
||||
|
||||
<?php if(get_role_id() == 5): ?>
|
||||
<a class="dropdown-item delete" data-id="<?= $row['id'];?>" onclick="removePolicyTransaction(this, '<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>', <?= $row['policy_type_id'] ?>)">
|
||||
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@ -673,6 +637,66 @@ function getAddPage(){
|
||||
}
|
||||
}
|
||||
|
||||
var inceptionTableFilters = <?= json_encode($inception_filters ?? []) ?>;
|
||||
var inceptionListDataTableUrl = '<?= base_url('policy_tranction/inception/list/datatable') ?>';
|
||||
var inceptionClearCacheUrl = '<?= base_url('policy_tranction/inception/list/clear-cache') ?>';
|
||||
var inceptionAutoReloadTimer = null;
|
||||
|
||||
function scheduleInceptionAutoReload(ms) {
|
||||
if (inceptionAutoReloadTimer) {
|
||||
clearTimeout(inceptionAutoReloadTimer);
|
||||
}
|
||||
if (ms > 0) {
|
||||
inceptionAutoReloadTimer = setTimeout(function() {
|
||||
window.location.reload();
|
||||
}, ms);
|
||||
}
|
||||
}
|
||||
|
||||
function exportServerSideFilteredInceptionData(e, dt, button, config, buttonType) {
|
||||
var self = this;
|
||||
var oldStart = dt.page.info().start;
|
||||
|
||||
dt.one('preXhr', function (x, s, data) {
|
||||
data.start = 0;
|
||||
data.length = -1;
|
||||
});
|
||||
|
||||
dt.one('draw', function () {
|
||||
$.fn.dataTable.ext.buttons[buttonType].action.call(self, e, dt, button, config);
|
||||
|
||||
dt.one('preXhr', function (x, s, data) {
|
||||
data.start = oldStart;
|
||||
data.length = dt.page.len();
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
dt.ajax.reload(null, false);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
dt.ajax.reload();
|
||||
}
|
||||
|
||||
function clearInceptionCacheAndReloadTable(dt) {
|
||||
$.ajax({
|
||||
url: inceptionClearCacheUrl,
|
||||
type: 'POST',
|
||||
success: function(response) {
|
||||
if (response && response.status) {
|
||||
inceptionTableFilters.cache_version = new Date().getTime();
|
||||
dt.ajax.reload(null, true);
|
||||
toastr.success(response.message || 'Cache cleared and list reloaded.', 'Success');
|
||||
} else {
|
||||
toastr.warning((response && response.message) ? response.message : 'Unable to clear cache.', 'Warning');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
toastr.error('Failed to clear cache.', 'Error');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Datatable document ready
|
||||
$(document).ready(function() {
|
||||
|
||||
@ -692,64 +716,109 @@ $(document).ready(function() {
|
||||
var ticketsTable = $('#tickets-table');
|
||||
|
||||
if (ticketsTable.length) {
|
||||
ticketsTable.DataTable({
|
||||
scrollX: true,
|
||||
// dom: "<'row'<'col-12'f><'col-sm-11 text-right'B>>" + // Filter left, buttons right
|
||||
// dom: "<'row'<'col-12 d-flex justify-content-between'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
|
||||
// "<'row'<'col-sm-12'tr>>" +
|
||||
// "<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
|
||||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||||
nhanceListDataTableBeforeInit();
|
||||
var inceptionTable = ticketsTable.DataTable(nhanceMergeListDataTableOptions({
|
||||
autoWidth: false,
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
deferRender: true,
|
||||
searchDelay: 400,
|
||||
columns: (function() {
|
||||
var cols = [];
|
||||
for (var i = 0; i < 16; i++) {
|
||||
cols.push({ data: String(i), orderable: false });
|
||||
}
|
||||
return cols;
|
||||
})(),
|
||||
ajax: {
|
||||
url: inceptionListDataTableUrl,
|
||||
type: 'POST',
|
||||
data: function(d) {
|
||||
return $.extend({}, d, inceptionTableFilters);
|
||||
},
|
||||
dataSrc: function(json) {
|
||||
scheduleInceptionAutoReload(json.cache_expires_in_ms || 300000);
|
||||
return json.data;
|
||||
}
|
||||
},
|
||||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" +
|
||||
"<'row'<'col-sm-12'tr>>" +
|
||||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="mdi mdi-filter" ></i><span class=" btn-custom"> Filter </span>',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
action: function(e, dt, node, config) {
|
||||
openPolicyFilterNav();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '<i class="mdi mdi-plus" ></i><span class=" btn-custom"> Add </span>',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
action: function (e, dt, node, config) {
|
||||
openPolicyNoAddModal();
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'collection',
|
||||
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
|
||||
className: 'btn app-btn-secondary ',
|
||||
buttons: [
|
||||
{
|
||||
extend: 'csv',
|
||||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||
className: 'app-btn-primary ',
|
||||
title: 'Policy-Tranction-Inception-List',
|
||||
exportOptions: {
|
||||
columns: ':not(:last-child)'
|
||||
},
|
||||
}
|
||||
]
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="mdi mdi-refresh" ></i><span class=" btn-custom"> Reload </span>',
|
||||
className: 'btn app-btn-secondary mr-2',
|
||||
action: function(e, dt) {
|
||||
clearInceptionCacheAndReloadTable(dt);
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
text: '<i class="mdi mdi-filter" ></i><span class=" btn-custom"> Filter </span>',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
action: function() {
|
||||
openPolicyFilterNav();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '<i class="mdi mdi-plus" ></i><span class=" btn-custom"> Add </span>',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
action: function () {
|
||||
openPolicyNoAddModal();
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'collection',
|
||||
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
|
||||
className: 'btn app-btn-secondary ',
|
||||
buttons: [
|
||||
{
|
||||
extend: 'csv',
|
||||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||
className: 'app-btn-primary ',
|
||||
title: 'Policy-Tranction-Inception-List',
|
||||
action: function (e, dt, button, config) {
|
||||
exportServerSideFilteredInceptionData.call(this, e, dt, button, config, 'csvHtml5');
|
||||
},
|
||||
exportOptions: {
|
||||
modifier: { search: 'applied', page: 'all' },
|
||||
columns: ':not(:last-child)'
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'excel',
|
||||
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
|
||||
className: 'app-btn-primary ',
|
||||
title: 'Policy-Tranction-Inception-List',
|
||||
action: function (e, dt, button, config) {
|
||||
exportServerSideFilteredInceptionData.call(this, e, dt, button, config, 'excelHtml5');
|
||||
},
|
||||
exportOptions: {
|
||||
modifier: { search: 'applied', page: 'all' },
|
||||
columns: ':not(:last-child)'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
language: {
|
||||
search: `
|
||||
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
|
||||
_INPUT_
|
||||
<i class="mdi mdi-magnify datatable-search-icon"
|
||||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||||
<i class="mdi mdi-close-circle datatable-clear-icon"
|
||||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
|
||||
</div>`,
|
||||
searchPlaceholder: "Search",
|
||||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||||
search: `
|
||||
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
|
||||
_INPUT_
|
||||
<i class="mdi mdi-magnify datatable-search-icon"
|
||||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||||
<i class="mdi mdi-close-circle datatable-clear-icon"
|
||||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
|
||||
</div>`,
|
||||
searchPlaceholder: "Search",
|
||||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||||
},
|
||||
paging: true, // Enable pagination
|
||||
pageLength: 10, // Set default number of rows per page (optional)
|
||||
// ordering: false,
|
||||
});
|
||||
paging: true,
|
||||
pageLength: 10,
|
||||
ordering: false,
|
||||
}));
|
||||
nhanceListDataTableAfterInit();
|
||||
nhanceListDataTableBindAdjust(inceptionTable);
|
||||
} else {
|
||||
console.error("Table not found.");
|
||||
}
|
||||
|
||||
@ -165,130 +165,6 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (isset($report_list)) { ?>
|
||||
<?php foreach($report_list as $index => $row){ ?>
|
||||
<tr data-id="<?= $row['pt_id'] ?>">
|
||||
<td><?= $index + 1 ?> <a href="<?php
|
||||
if(strtolower($row['action_type']) == "policy"){
|
||||
echo base_url('policy_tranction/inception/list') . '?pt_id=' . $row['id'] ;
|
||||
}else{
|
||||
echo base_url('policy_tranction/endorsement/list') . '?pt_id=' . $row['id'] ;
|
||||
}
|
||||
?>" class="mdi mdi-pencil" ></a> </td>
|
||||
<td><?php echo $row['user_name'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['policy_issue_month'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['revenue_type'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['client_type'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['client_name'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['action_type'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['policy_type'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['bap'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['vehicle_no'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['policy_no'] ?: 'N/A'; ?></td>
|
||||
<td><?php echo $row['endorsement_no'] ?: 'N/A'; ?></td>
|
||||
<!-- <td style="display: none;"><?php echo $row['insurer_name'] ?: 'N/A'; ?> </td> -->
|
||||
<td><?php echo $row['insurer_branch_name'] ?: 'N/A'; ?></td>
|
||||
<!-- <td style="display: none;"><?php echo $row['tpa_name']; ?></td> -->
|
||||
<td style="display: none;"><?php echo empty($row['endorse_eff_date']) ? 'N/A' : change_date_format($row['endorse_eff_date'], 'Y-m-d', 'd/m/Y') ?></td>
|
||||
<td style="display: none;"><?php echo empty($row['policy_start_date']) ? 'N/A' : change_date_format($row['policy_start_date'], 'Y-m-d', 'd/m/Y'); ?></td>
|
||||
<td style="display: none;"><?php echo empty($row['policy_end_date']) ? 'N/A' : change_date_format($row['policy_end_date'], 'Y-m-d', 'd/m/Y'); ?></td>
|
||||
<td style="display: none;"><?php echo $row['ref'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['remarks'] ?: 'N/A'; ?></td>
|
||||
|
||||
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['bp_amt'] ?: '0.00') : '0.00'; ?></td>
|
||||
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['tp_or_ter'] ?: '0.00') : '0.00'; ?></td>
|
||||
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['premium_wo_gst'] ?: '0.00') : '0.00'; ?></td>
|
||||
<!-- <td class="right-align-input" style="display: none;"><?php echo $row['gst_amount']; ?></td> -->
|
||||
<td class="right-align-input" style="display: none;"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['total_premium'] ?: '0.00') : '0.00'; ?></td>
|
||||
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['agreed_bp_per'] ?: '0.00') : '0.00'; ?>%</td>
|
||||
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['agreed_tp_or_ter_per'] ?: '0.00') : '0.00'; ?>%</td>
|
||||
<td class="right-align-input"><?php echo isset($row['reward']) ? $row['reward'] : '0.00'; ?></td>
|
||||
|
||||
<?php
|
||||
// Below Line its old version i am removed. reason no value ['total_irda_amt'] means taken as ['exp_amt'] so.
|
||||
// LN156 - $total_irda_amt = empty($row['total_irda_amt']) ? $row['exp_amt'] : $row['total_irda_amt'];
|
||||
// Here i am compare [total_irda_amt] and [exp_amt] i am print the larger value.
|
||||
// both are equal, print either value.
|
||||
// both are zero , empty/null , any one is empty or null means => i am print 0.00.
|
||||
// REF : Velmurugan but he told handle in query
|
||||
// Date : 6/11/25 12:50
|
||||
$irda_amt = isset($row['total_irda_amt']) && $row['total_irda_amt'] !== '' ? (float)$row['total_irda_amt'] : 0;
|
||||
$exp_amt = isset($row['exp_amt']) && $row['exp_amt'] !== '' ? (float)$row['exp_amt'] : 0;
|
||||
// $max_amount = max($irda_amt, $exp_amt);
|
||||
// $total_irda_amt = number_format($max_amount, 2, '.', '');
|
||||
// $total_irda_amt = empty($row['total_irda_amt']) ? $row['exp_amt'] : $row['total_irda_amt'];
|
||||
$total_irda_amt = $row['total_irda_amt'] ?? '0.00';
|
||||
?>
|
||||
<td class="right-align-input" onclick="showCoShareStatementDetails(this)" data-id="<?= $row['pt_id'] ?>"><?php echo $total_irda_amt; ?></td>
|
||||
<td class="right-align-input" data-id="<?php echo strtolower($row['action_type']) ?: '-'; ?>"><?php echo empty($row['billed_amt']) ? '0.00' : $row['billed_amt'] ?></td>
|
||||
<!-- <td class="right-align-input"><?php echo empty($row['unbilled_amt']) ? '0.00' : $row['unbilled_amt']?></td> -->
|
||||
<?php
|
||||
// Below Line its old version so commanded reason they direct taken as ['total_irda_amt'] from array.
|
||||
// $unbilled_amt = $row['total_irda_amt'] - $row['billed_amt'];
|
||||
// now stored total_irda_amt value taken here
|
||||
// REF : Velmurugan but he told handle in query
|
||||
// Date : 6/11/25 12:50
|
||||
$unbilled_amt = $total_irda_amt - $row['billed_amt'];
|
||||
if($total_irda_amt == "0.00"){
|
||||
$unbilled_amt = abs($unbilled_amt);
|
||||
}
|
||||
$unbilled_amt = $unbilled_amt == 0 && $row['billed_amt'] == 0 ? $total_irda_amt : $unbilled_amt ;
|
||||
?>
|
||||
<td class="right-align-input">
|
||||
<?php echo
|
||||
// number_format((float)$unbilled_amt,2, '.', '')
|
||||
// number_format((float) ($row['unbilled_amount'] ?: 0), 2, '.', '');
|
||||
$unbilled = isset($row['unbilled_amount']) ? $row['unbilled_amount'] : '0.00';
|
||||
number_format($unbilled, 2, '.', '');
|
||||
?>
|
||||
</td>
|
||||
<td style="display: none;"><?php echo $row['salse_person_name'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['service_person_name'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['nhance_branch'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo $row['installment'] ?: 'N/A'; ?></td>
|
||||
<td style="display: none;"><?php echo empty($row['data_received_date']) ? 'N/A' : change_date_format($row['data_received_date'], 'Y-m-d', 'd/m/Y') ?></td>
|
||||
<td style="display: none;"><?php echo empty($row['renewal_date']) ? 'N/A' : change_date_format($row['renewal_date'], 'Y-m-d', 'd/m/Y') ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo $row['co_share'] ?? 'No'; ?></td>
|
||||
<td style="display:none;"><?php echo $row['bro_payable_by'] ?? 'No'; ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo $row['salse_manager_name'] ?: 'N/A'; ?></td>
|
||||
<td style="display:none;"><?php echo $row['service_manager_name'] ?: 'N/A'; ?></td>
|
||||
<td style="display:none;"><?php echo $row['service_branch'] ?: 'N/A'; ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo empty($row['rollover_date']) ? 'N/A' : change_date_format($row['rollover_date'], 'Y-m-d', 'd/m/Y') ?? 'N/A'; ?> </td>
|
||||
|
||||
<td style="display:none;"><?php echo $row['policy_holder_name'] ?: 'N/A'; ?></td>
|
||||
<td style="display:none;"><?php echo $row['same_as_proposer'] ?? 'No'; ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo $row['follower_policy_no'] ?: 'N/A'; ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['co_share_per'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['non_comm_per_amt'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['bp_igst'] ?? 0), 2); ?></td>
|
||||
<td style="display:none;"><?php echo number_format((float)($row['bp_sgst'] ?? 0), 2); ?></td>
|
||||
<td style="display:none;"><?php echo number_format((float)($row['bp_cgst'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['stamp_duty'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['standerd_bp_per'] ?? 0), 2); ?></td>
|
||||
<td style="display:none;"><?php echo number_format((float)($row['standerd_tp_per'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['actual_bp_amt'] ?? 0), 2); ?></td>
|
||||
<td style="display:none;"><?php echo number_format((float)($row['actual_tp_amt'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['actual_bp_per'] ?? 0), 2); ?></td>
|
||||
<td style="display:none;"><?php echo number_format((float)($row['actual_tp_per'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo number_format((float)($row['actual_tep_brokerage_amt'] ?? 0), 2); ?></td>
|
||||
<td style="display:none;"><?php echo number_format((float)($row['actual_tp_brokerage_amt'] ?? 0), 2); ?></td>
|
||||
|
||||
<td style="display:none;"><?php echo $row['cd_ac_no'] ?: 'N/A'; ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@ -332,6 +208,68 @@
|
||||
<!-------------------------------------------------------------------------------------------------->
|
||||
|
||||
<script>
|
||||
var bdsReportFilters = <?= json_encode($bds_filters ?? []) ?>;
|
||||
var bdsReportDataTableUrl = '<?= base_url('policy_tranction/report/list/datatable') ?>';
|
||||
var bdsReportClearCacheUrl = '<?= base_url('policy_tranction/report/list/clear-cache') ?>';
|
||||
|
||||
function updateBdsReportTotals(totals) {
|
||||
if (!totals) {
|
||||
return;
|
||||
}
|
||||
$('#total_premium').text(totals.total_premium || '0.00');
|
||||
$('#total_rewards').text(totals.total_rewards || '0.00');
|
||||
$('#total_irda').text(totals.total_irda || '0.00');
|
||||
$('#total_revenue').text(totals.total_revenue || '0.00');
|
||||
$('#total_billed').text(totals.total_billed || '0.00');
|
||||
$('#total_unbilled').text(totals.total_unbilled || '0.00');
|
||||
}
|
||||
|
||||
// Export all filtered rows in server-side DataTable (not only current page).
|
||||
function exportServerSideFilteredData(e, dt, button, config, buttonType) {
|
||||
var self = this;
|
||||
var oldStart = dt.page.info().start;
|
||||
|
||||
dt.one('preXhr', function (x, s, data) {
|
||||
data.start = 0;
|
||||
data.length = -1; // backend converts -1 to all filtered rows
|
||||
});
|
||||
|
||||
dt.one('draw', function () {
|
||||
$.fn.dataTable.ext.buttons[buttonType].action.call(self, e, dt, button, config);
|
||||
|
||||
dt.one('preXhr', function (x, s, data) {
|
||||
data.start = oldStart;
|
||||
data.length = dt.page.len();
|
||||
});
|
||||
|
||||
// Restore the previous page after export.
|
||||
setTimeout(function () {
|
||||
dt.ajax.reload(null, false);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
dt.ajax.reload();
|
||||
}
|
||||
|
||||
function clearBdsCacheAndReloadTable(dt) {
|
||||
$.ajax({
|
||||
url: bdsReportClearCacheUrl,
|
||||
type: 'POST',
|
||||
success: function(response) {
|
||||
if (response && response.status) {
|
||||
bdsReportFilters.cache_version = new Date().getTime();
|
||||
dt.ajax.reload(null, true);
|
||||
toastr.success(response.message || 'Cache cleared and list reloaded.', 'Success');
|
||||
} else {
|
||||
toastr.warning((response && response.message) ? response.message : 'Unable to clear cache.', 'Warning');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
toastr.error('Failed to clear cache.', 'Error');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Datatable document ready
|
||||
$(document).ready(function() {
|
||||
|
||||
@ -341,6 +279,45 @@ $(document).ready(function() {
|
||||
nhanceListDataTableBeforeInit();
|
||||
var nhBdsReportTable = ticketsTable.DataTable(nhanceMergeListDataTableOptions({
|
||||
autoWidth: false,
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
deferRender: true,
|
||||
searchDelay: 400,
|
||||
columns: (function() {
|
||||
var cols = [];
|
||||
for (var i = 0; i < 58; i++) {
|
||||
cols.push({ data: String(i), orderable: false });
|
||||
}
|
||||
return cols;
|
||||
})(),
|
||||
ajax: {
|
||||
url: bdsReportDataTableUrl,
|
||||
type: 'POST',
|
||||
data: function(d) {
|
||||
return $.extend({}, d, bdsReportFilters);
|
||||
},
|
||||
dataSrc: function(json) {
|
||||
updateBdsReportTotals(json.totals);
|
||||
return json.data;
|
||||
}
|
||||
},
|
||||
columnDefs: [
|
||||
{ targets: [18, 19, 20, 21, 22, 23, 24, 25, 26, 27], className: 'right-align-input' },
|
||||
{
|
||||
targets: [
|
||||
3, 4, 8, 9, 13, 14, 15, 16, 17, 21,
|
||||
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
|
||||
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
|
||||
52, 53, 54, 55, 56, 57
|
||||
],
|
||||
visible: false
|
||||
}
|
||||
],
|
||||
createdRow: function(row, data) {
|
||||
if (data.DT_RowAttr) {
|
||||
$(row).attr(data.DT_RowAttr);
|
||||
}
|
||||
},
|
||||
// dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + // Filter left, buttons right
|
||||
// "<'row'<'col-sm-12'tr>>" +
|
||||
// "<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
|
||||
@ -400,6 +377,13 @@ $(document).ready(function() {
|
||||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||||
buttons: [
|
||||
{
|
||||
text: '<i class="mdi mdi-refresh" ></i><span class=" btn-custom"> Reload </span>',
|
||||
className: 'btn app-btn-secondary mr-2',
|
||||
action: function(e, dt) {
|
||||
clearBdsCacheAndReloadTable(dt);
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '<i class="mdi mdi-filter" ></i><span class=" btn-custom"> Filter </span>',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
@ -416,7 +400,14 @@ $(document).ready(function() {
|
||||
extend: 'csv',
|
||||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||
title: 'Policy-Tranction-BDS-List',
|
||||
action: function (e, dt, button, config) {
|
||||
exportServerSideFilteredData.call(this, e, dt, button, config, 'csvHtml5');
|
||||
},
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
search: 'applied',
|
||||
page: 'all'
|
||||
},
|
||||
columns: function (idx, data, node) {
|
||||
return true; // ✅ include all columns (even hidden)
|
||||
},
|
||||
@ -465,6 +456,9 @@ $(document).ready(function() {
|
||||
sheetName: 'Policy-Tranction-BDS-List',
|
||||
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
|
||||
className: 'app-btn-primary ',
|
||||
action: function (e, dt, button, config) {
|
||||
exportServerSideFilteredData.call(this, e, dt, button, config, 'excelHtml5');
|
||||
},
|
||||
// customize: function (xlsx) {
|
||||
// var sheet = xlsx.xl.worksheets['sheet1.xml'];
|
||||
// var total = 0;
|
||||
@ -559,6 +553,10 @@ $(document).ready(function() {
|
||||
$(sheet).find('sheetData').append(totalRow);
|
||||
},
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
search: 'applied',
|
||||
page: 'all'
|
||||
},
|
||||
orthogonal: 'sort'
|
||||
},
|
||||
customizeData: function (data) {
|
||||
@ -587,134 +585,9 @@ $(document).ready(function() {
|
||||
searchPlaceholder: "Search",
|
||||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||||
},
|
||||
paging: true, // Enable pagination
|
||||
pageLength: 10, // Set default number of rows per page (optional)
|
||||
paging: true,
|
||||
pageLength: 10,
|
||||
ordering: false,
|
||||
// "footerCallback": function(row, data, start, end, display) {
|
||||
// var api = this.api();
|
||||
|
||||
// // Calculate column totals
|
||||
// var totalPremium = api.column(23).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b) || 0;
|
||||
// }, 0);
|
||||
|
||||
// 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;
|
||||
// }, 0);
|
||||
|
||||
// var totalBilled = api.column(28).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b) || 0;
|
||||
// }, 0);
|
||||
|
||||
// var totalUnbilled = api.column(29).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b) || 0;
|
||||
// }, 0);
|
||||
|
||||
// // Update the totals in the div above the table
|
||||
// $('#total_premium').text(totalPremium.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));
|
||||
// }
|
||||
"footerCallback": function(row, data, start, end, display) {
|
||||
var api = this.api();
|
||||
|
||||
// Calculate column totals (adjust indices based on VISIBLE columns)
|
||||
// var totalPremium = api.column(20, {search: 'applied'}).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b || 0);
|
||||
// }, 0);
|
||||
|
||||
// var total_rewards = api.column(23, {search: 'applied'}).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b || 0);
|
||||
// }, 0);
|
||||
|
||||
// var totalIrda = api.column(24, {search: 'applied'}).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b || 0);
|
||||
// }, 0);
|
||||
|
||||
// var totalBilled = api.column(25, {search: 'applied'}).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b || 0);
|
||||
// }, 0);
|
||||
|
||||
// var totalUnbilled = api.column(26, {search: 'applied'}).data().reduce(function(a, b) {
|
||||
// return parseFloat(a) + parseFloat(b || 0);
|
||||
// }, 0);
|
||||
|
||||
// Update the totals
|
||||
// $('#total_premium').text(totalPremium.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));
|
||||
|
||||
var getUniqueUnbilled = function(colIndex) {
|
||||
|
||||
var rows = api.rows({ search: 'applied' }).nodes(); // get filtered nodes
|
||||
var maxRowPerId = {}; // store only the greatest row
|
||||
|
||||
$(rows).each(function() {
|
||||
var rowId = $(this).data('id'); // read data-id
|
||||
var rowIndex = $(this).index(); // row index
|
||||
|
||||
// Keep only the greatest row index per data-id
|
||||
if (!maxRowPerId[rowId] || rowIndex > maxRowPerId[rowId]) {
|
||||
maxRowPerId[rowId] = rowIndex;
|
||||
}
|
||||
});
|
||||
|
||||
var total = 0;
|
||||
|
||||
// Now sum only the selected rows
|
||||
$.each(maxRowPerId, function(id, rowIndex) {
|
||||
var value = api.cell(rowIndex, colIndex).data();
|
||||
value = parseFloat((typeof value === 'string') ? value.replace(/[^0-9.\-]+/g, '') : value) || 0;
|
||||
total += value;
|
||||
});
|
||||
|
||||
return total;
|
||||
};
|
||||
|
||||
// Helper to sum numeric values safely
|
||||
var getTotal = function(colIndex) {
|
||||
return api.column(colIndex, { search: 'applied' }).data()
|
||||
.reduce(function(a, b) {
|
||||
var x = parseFloat(a) || 0;
|
||||
var y = parseFloat(
|
||||
(typeof b === 'string') ? b.replace(/[^0-9.\-]+/g, '') : b
|
||||
) || 0;
|
||||
return x + y;
|
||||
}, 0);
|
||||
};
|
||||
|
||||
// Compute totals by column index
|
||||
var totalPremium = getTotal(20);
|
||||
var totalRewards = getTotal(24);
|
||||
var totalIrda = getTotal(25);
|
||||
var totalBilled = getTotal(26);
|
||||
var totalUnbilled = getTotal(27);
|
||||
|
||||
var totalIrdaAmt = parseFloat(totalBilled) - parseFloat(totalRewards);
|
||||
var totalRevenue = parseFloat(totalIrdaAmt) + parseFloat(totalRewards);
|
||||
|
||||
// Update the totals section above the table
|
||||
$('#total_premium').text(totalPremium.toFixed(2));
|
||||
$('#total_rewards').text(totalRewards.toFixed(2));
|
||||
// $('#total_irda').text(totalIrda.toFixed(2));
|
||||
$('#total_irda').text(totalIrdaAmt.toFixed(2));
|
||||
$('#total_revenue').text(totalRevenue.toFixed(2));
|
||||
// $('#total_revenue').text(totalIrda.toFixed(2));
|
||||
$('#total_billed').text(totalBilled.toFixed(2));
|
||||
$('#total_unbilled').text(totalUnbilled.toFixed(2));
|
||||
// var totalUnbilled = getUniqueUnbilled(27);
|
||||
// $('#total_unbilled').text(totalUnbilled.toFixed(2));
|
||||
}
|
||||
}));
|
||||
nhanceListDataTableAfterInit();
|
||||
nhanceListDataTableBindAdjust(nhBdsReportTable);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user