diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 9c1b388e..ef4c655c 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -360,6 +360,9 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get('removeInstallments', 'LeadsController::removeInstallments');
});
+$routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail");
+$routes->cli("cli/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail");
+
$routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
$routes->group("inception", ["filter" => "authMVC"], function ($routes) {
@@ -545,6 +548,7 @@ $routes->group("/bdsReport", ["filter" => "authMVC"], function ($routes) {
$routes->group("/ticket", ["filter" => "authMVC"], function ($routes) {
$routes->match( ['get', 'post'], 'list','TicketController::ticketList');
$routes->get('feedback-list','TicketController::feedbackList');
+ $routes->get('remove','TicketController::removeTicket');
$routes->get('new/(:any)','TicketController::ticket_form/$1');
$routes->post('create','TicketController::createTicket');
$routes->post('update','TicketController::updateTicket');
diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 39440f05..9bf373ce 100755
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -44,6 +44,7 @@ use App\Models\ClientApiModel;
use App\Controllers\EmpDataServiceController;
use App\Controllers\GoogleDriveController;
+use App\Controllers\PolicyTransactionController;
use App\Helpers\sendMailNotification;
use App\Models\PTCOShareDetailsModel;
@@ -4608,6 +4609,10 @@ class ClientController extends AdminController
// $res = $empServiceController->excelFileDataValidation(['file_id' => '865']);
// $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '829']);
// $res = $empServiceController->employeeDisembark(['file_id' => '858']);
+
+ $policyTransactionController = new PolicyTransactionController();
+ // $res = $policyTransactionController->validateInsurerStatement(['file_id' => '17']);
+ // $res = $policyTransactionController->updateInsurerStatement(['file_id' => '22']);
// dd('-----', $res);
@@ -4680,7 +4685,7 @@ class ClientController extends AdminController
// ------------- LEADS CONTROLLER ----------------------------------------------------------
- // $LeadsController = new LeadsController();
+ $LeadsController = new LeadsController();
// $RFQModel = new RFQModel();
// $data = $RFQModel->where('is_active', 1)->where('lead_id', 40)->first();
@@ -4694,6 +4699,8 @@ class ClientController extends AdminController
// $returndata = $LeadsController->convertQCRJsonToPolicyTerms($jsonArray, $policy_type, $proposel_name, $insurer_name);
// dd($returndata);
+ $LeadsController->handleMemberDataGPATotalSumInsurerFromExcel(['lead_id' => 169]);
+
// -----------BDS REPORT CONTROLLER---------------------------------------------------------------------------------
// $BDSReportController = new BDSReportController();
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index a11921fb..0bcc03c5 100755
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -444,6 +444,8 @@ class EmployeeController extends AdminController
$filePath = ROOTPATH . 'public/sample_excel/enrollment.xlsx';
}else if ($actionType == 'missed_inception') {
$filePath = ROOTPATH . 'public/sample_excel/sample_inception.xls';
+ }else if ($actionType == 'member_data') {
+ $filePath = ROOTPATH . 'public/sample_excel/Sample_Member_Data.xlsx';
}
// Check if the file exists
diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php
index 31c2ff0f..5d65c4a4 100755
--- a/app/Controllers/EmployeeServiceController.php
+++ b/app/Controllers/EmployeeServiceController.php
@@ -1383,11 +1383,11 @@ class EmployeeServiceController extends AdminController
{
// dd($employee);
$existing_endorsements = $this->empEndorsementModel->where('actions','d')
- ->where('table_name','employees')
+ ->where('table_name','employee_polices')
->where('endorsement_id is null')
->where('emp_code',$employee['emp_code'])
->where('name',$employee['name'])
- ->where('field_name','emp_status')
+ ->where('field_name','status')
->where('status !=','truncated')
->where('is_active', 1)
->findAll();
@@ -2087,12 +2087,14 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){
$relation = 'parent';
} else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){
$relation = 'child';
- }else if(strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law'){
+ }else if((strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law') || (strtolower(trim($value['relationship'])) === 'father-in-law' || strtolower(trim($value['relationship'])) === 'mother-in-law')){
$relation = 'parent_in_law';
}else if(strtolower(trim($value['relationship'])) === 'spouse'){
$relation = 'spouse';
- }else{
+ }else if(strtolower(trim($value['relationship'])) === 'self'){
$relation = 'self';
+ }else {
+ $relation = '';
}
$value['family_floater_key'] = $relation;
diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php
index b001edf1..6e6c6952 100644
--- a/app/Controllers/LeadsController.php
+++ b/app/Controllers/LeadsController.php
@@ -712,6 +712,12 @@ class LeadsController extends BaseController
$subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}}";
}
+ if($lead_data['policy_type_id'] == 1){
+ $data['totalSumAssured'] = $this->handleMemberDataGPATotalSumInsurerFromExcel(['lead_id' => $id]);
+ }else{
+ $data['totalSumAssured'] = [];
+ }
+
$data['mail_content'] = $this->transformMailContent($lead_data, $mail_content, $data['page_name']);
$data['subject'] = $this->transformMailContent($lead_data, $subject, $data['page_name']);
@@ -1762,7 +1768,7 @@ class LeadsController extends BaseController
['file_path' => WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'], 'sheets' => [0, 1]],
['file_path' => WRITEPATH . '/uploads/lead_files/' . $result['filename'], 'sheets' => []],
];
- $outputPath = WRITEPATH . 'uploads/lead_files/Member_Data.xlsx';
+ $outputPath = WRITEPATH . 'uploads/lead_files/' .$lead_data['file_name'];
$result_merge = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath);
if ($result_merge) {
// Call the delete function after the file is successfully created
@@ -2372,7 +2378,9 @@ class LeadsController extends BaseController
$installment_data = json_decode($params['installments'], true);
if(!empty($installment_data)){
foreach ($installment_data as $key => $value) {
- $value['payment_date'] = date('Y/m/d', strtotime($value['payment_date'])) ?? null;
+ $value['payment_date'] = !empty($value['payment_date']) && strtotime($value['payment_date'])
+ ? date('Y/m/d', strtotime($value['payment_date']))
+ : null;
if(isset($value['id']) && !empty($value['id'])){
$this->leadInstallmentPaymentDetails->where('id', $value['id'])->set($value)->update();
}else{
@@ -4077,4 +4085,71 @@ class LeadsController extends BaseController
return $attachments;
}
+
+ public function handleMemberDataGPATotalSumInsurerFromExcel($params)
+ {
+ $lead_id = $params['lead_id'];
+ $lead_data = $this->leadsModel->find($lead_id);
+ // dd($lead_data);
+ $file_name_with_path = WRITEPATH . "/uploads/lead_files/" . $lead_data['file_name'];
+ // dd($file_name_with_path);
+
+ if (!$lead_data) {
+ return ['status' => 'failed', 'message' => 'Lead data not found'];
+ }
+
+ if ($lead_data['file_name']) {
+
+ //check physical file
+ if (!file_exists($file_name_with_path)) {
+
+ $message = "Lead Physcial file not found";
+ $this->myLogger->logme('error', ($message . ' for file ' . $file_name_with_path));
+ return ['status' => 'failed', 'message' => 'no physical file'];
+ }
+
+ $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
+
+ //get members data
+ $members_sheet = $spreadsheet->getSheet(0);
+ $highestRowAndColumn = $members_sheet->getHighestRowAndColumn();
+ // dd($highestRowAndColumn);
+
+ $uncleaned_members = $members_sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
+ // dd($uncleaned_members);
+
+ $members = ExcelSanitizeHelper::sanitizeArrayData($uncleaned_members);
+ // dd($members);
+
+
+ // Check column headings
+ $members_heading = $members[0];
+ $available_col = [];
+
+ $lower_headers = array_map('strtolower', $members_heading);
+ foreach ($lower_headers as $index => $header) {
+ if (preg_match('/^sa\s*-\s*option\s*\d*$/i', $header)) {
+ $column_name = $members_heading[$index];
+ $sum = 0;
+
+ for ($i = 1; $i < count($members); $i++) {
+ $cell_raw = $members[$i][$index] ?? '';
+ $cell_clean = preg_replace('/[^0-9.\-]/', '', $cell_raw); // remove non-numeric chars
+
+ if ($cell_clean !== '' && is_numeric($cell_clean)) {
+ $sum += (float) $cell_clean;
+ }
+ }
+
+ $available_col[] = $sum;
+ }
+ }
+
+
+ // dd($available_col);
+ return $available_col;
+ }
+
+ return [];
+ }
}
diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php
index fa094bb8..0a3c357d 100755
--- a/app/Controllers/MasterController.php
+++ b/app/Controllers/MasterController.php
@@ -1680,7 +1680,7 @@ class MasterController extends AdminController
["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"],
["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"]
];
- $email_id = 'srinivas.saravanan@venbainfotech.com';
+ $email_id = ['srinivas.saravanan@venbainfotech.com','srinivassaravanan2002@gmail.com'];
$params = ['mail'=>$email_id];
$common = ['mail_type'=>'test_mail_cli'];
// $bcc = "vijayalakshmi@nhanceindia.in,vitvelz@gmail.com,velmurugan.s@venbainfotech.com,hariharan@nhanceindia.in,hariharan@jubiliant.in,srinivas.saravanan@venbainfotech.com";
diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php
index 310cc939..d7270335 100644
--- a/app/Controllers/PolicyTransactionController.php
+++ b/app/Controllers/PolicyTransactionController.php
@@ -32,10 +32,13 @@ use App\Models\InvPaymentDetailsModel;
use App\Models\BatchFileModel;
use App\Models\FileModel;
use App\Models\COShareStmtDetailsModel;
-use Kint;
+use App\Models\BdsPlacementModel;
+use Kint\Kint;
+use App\Helpers\MailHelper;
+use Exception;
class PolicyTransactionController extends BaseController
-{
+{
use ResponseTrait;
protected $myLogger;
@@ -64,6 +67,7 @@ class PolicyTransactionController extends BaseController
protected $batchFileModel;
protected $filesModel;
protected $coShareStmtDetailsModel;
+ protected $BdsPlacementModel;
public function __construct()
{
@@ -94,6 +98,7 @@ class PolicyTransactionController extends BaseController
$this->batchFileModel = new BatchFileModel();
$this->filesModel = new FileModel();
$this->coShareStmtDetailsModel = new COShareStmtDetailsModel();
+ $this->BdsPlacementModel = new BdsPlacementModel();
$this->invoiceStatus = [
'pending' => 'Pending',
'generated' => 'Generated',
@@ -182,8 +187,7 @@ class PolicyTransactionController extends BaseController
$issuer,
$status
);
-
- }else{
+ } else {
$ids = $this->request->getPost('ids');
$ids = array_filter(explode(',', $ids));
@@ -1831,7 +1835,7 @@ class PolicyTransactionController extends BaseController
if (isset($isFromDashboard) && !empty($isFromDashboard) && $isFromDashboard == 1) {
$ids = $this->request->getPost('ids');
-
+
$ids = array_filter(explode(',', $ids));
if (!empty($ids)) {
@@ -2380,7 +2384,7 @@ class PolicyTransactionController extends BaseController
if (($actual_bp_brokerage && $actual_bp_brokerage != 0 && $actual_bp_brokerage != "")) {
$total_amt += $actual_bp_brokerage;
//percentage reverse calculation
- if ($actual_bp_per == 0 || $actual_bp_per == "") {
+ if (($actual_bp_per == 0 || $actual_bp_per == 0) && !empty($actual_bp_amt)) {
$actual_bp_per = round(($actual_bp_brokerage / $actual_bp_amt) * 100, 2);
}
} else {
@@ -2395,7 +2399,7 @@ class PolicyTransactionController extends BaseController
if ($actual_tp_brokerage && $actual_tp_brokerage != 0 && $actual_tp_brokerage != "") {
$total_amt += $actual_tp_brokerage;
//percentage reverse calculation
- if ($actual_tp_per == 0 || $actual_tp_per == "") {
+ if (($actual_tp_per == 0 || $actual_tp_per == "") && !empty($actual_tp_amt)) {
$actual_tp_per = ($actual_tp_brokerage / $actual_tp_amt) * 100;
}
} else {
@@ -2410,7 +2414,7 @@ class PolicyTransactionController extends BaseController
if ($actual_tep_brokerage && $actual_tep_brokerage != 0 && $actual_tep_brokerage != "") {
$total_amt += $actual_tep_brokerage;
//percentage reverse calculation
- if ($actual_tep_per == 0 || $actual_tep_per == "") {
+ if (($actual_tep_per == 0 || $actual_tep_per == "") && !empty($actual_tep_amt)) {
$actual_tep_per = ($actual_tep_brokerage / $actual_tep_amt) * 100;
}
} else {
@@ -2801,4 +2805,105 @@ class PolicyTransactionController extends BaseController
->update();
return $this->respond(['dataStatus' => true, 'code' => 200], 200);
}
+
+ public function sendInstallmentRemainderMail()
+ {
+
+ $this->myLogger->logme("error", "Cron Job For Send Installment Remainder Mail Started");
+
+ try {
+
+ try {
+
+ $bdsInstallmentData = $this->BdsPlacementModel->getClientInstallmentDetails();
+
+ }catch (Exception $e) {
+
+ $this->myLogger->logme('error', 'Exception: ' . $e->getMessage() . 'Page: ' . $e->getFile() . ' Line: ' . $e->getLine());
+
+ }
+ $this->myLogger->logme("error", "Data for BDS Installment " . json_encode($bdsInstallmentData));
+ // dd($bdsInstallmentData);
+
+ if (empty($bdsInstallmentData)) {
+
+ $this->myLogger->logme("error", "No Client Installment is Due in the 15th Day");
+
+ return false;
+ }
+
+ foreach ($bdsInstallmentData as $installmentData) {
+
+ $mailData = $this->PrepareBDSMailData($installmentData);
+ $to_mail = $mailData['to_mail'];
+ $message = $mailData['message'];
+ $subject = $mailData['subject'];
+
+ $this->myLogger->logme("error", "Installment Pending for" . $subject);
+
+ $common = ['mail_type' => 'installment_amount_due_remainder_mail'];
+
+ $res = MailHelper::send_email(['mail' => $to_mail, 'subject' => $subject, 'message' => $message, 'common' => $common]);
+
+ $res = json_decode($res);
+ $this->myLogger->logme('error', 'res: ' . json_encode($res));
+
+ if ($res->status == 'success') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ } catch (Exception $e) {
+
+ $this->myLogger->logme('error', 'Exception: ' . $e->getMessage() . 'Page: ' . $e->getFile() . ' Line: ' . $e->getLine());
+ }
+ }
+
+ protected function PrepareBDSMailData($data)
+ {
+
+ try {
+
+ $installment_amount = $data['installment_amount'];
+ $payment_date = date('d-m-Y', strtotime($data['payment_date']));
+ $client = $data['client_name'];
+ $branch = $data['branch_name'];
+ $sales_person_mail = $data['sales_person'];
+ $heads = $data['heads'];
+ $admins = $data['admins'];
+ $buisness_team = $data['buisness_team'];
+ $policy_no = $data['policy_no'];
+ $client_short_name = isset($data['short_name']) && $data['short_name'] != null ? $data['short_name'] : $data['client_name'];
+
+ $subject = "Installment Amount Due For Client - {$client_short_name} - Policy NO({$policy_no}) is Due On - {$payment_date}";
+
+ $message = "Policy Installment for Client - {$client}, Branch - {$branch} is Due on {$payment_date}
+ with amount of {$installment_amount}.
+ Policy No : {$policy_no}";
+
+
+ $to_mail = array_merge(
+ array_column($heads, 'email'),
+ array_column($admins, 'email'),
+ array_column($buisness_team, 'email'),
+ [$sales_person_mail]
+ );
+
+ $to_mail = array_unique($to_mail);
+
+ $this->myLogger->logme("error", "Selected To Address : " . json_encode($to_mail));
+
+ // dd($to_mail);
+ return [
+ 'to_mail' => $to_mail,
+ 'message' => $message,
+ 'subject' => $subject
+ ];
+
+ } catch (Exception $e) {
+
+ $this->myLogger->logme('error', 'Exception: ' . $e->getMessage() . 'Page: ' . $e->getFile() . ' Line: ' . $e->getLine());
+ }
+ }
}
diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php
index 37685b55..005bebc4 100644
--- a/app/Controllers/TicketController.php
+++ b/app/Controllers/TicketController.php
@@ -198,6 +198,12 @@ class TicketController extends BaseController
}else if ($isFromDashboard == 2){
$data['ticket_data'] = $this->ticketSearch(4);
+ }else if ($isFromDashboard == 3){
+ $data['ticket_data'] = $this->ticketSearch(2);
+
+ }else if ($isFromDashboard == 4){
+ $data['ticket_data'] = $this->ticketSearch(5);
+
}
$data['claim_status'] = $this->claimStatus->select('id,ticket_type,claim_status')->where('is_active', 1)->findAll();
$data['client_list'] = $this->clientModel->select('id,client_name')->where('is_active', 1)->findAll();
@@ -249,7 +255,7 @@ class TicketController extends BaseController
->groupBy('tm.id, tm.created_at, latest_history.created_at');
- //action 1 get last 100 rows, action 2 filter and get all rows related to that, action 3 gets according to dashboard, action 4 gets according to ACM
+ //action 1 get last 100 rows, action 2 filter and get all rows related to that, action 3 gets according to dashboard, action 4 gets according to ACM, action 5 tat
if ($action == 1) {
$query = $db->table('ticket_master tm')
@@ -356,6 +362,10 @@ class TicketController extends BaseController
$where = '1 = 0'; // No valid IDs, return empty result
}
+ }else if ($action == 5) {
+ $search_data = $this->request->getPost();
+ $where = "tm.created_at >= '" . $search_data['from_date'] . "' AND tm.created_at <= '" . $search_data['to_date'] . "'" ."and ticket_type_id = ".$search_data['ticket_type_id'];
+
} else {
$search_data = $this->request->getPost();
// print_r($search_data); die()
@@ -445,6 +455,17 @@ class TicketController extends BaseController
->orderBy('tm.id', 'DESC');
$data = $query->get()->getResultArray();
+ // dd($db->getLastQuery()->getQuery());
+ // dd($data);
+ if ($action == 5){
+
+ $tat = $this->request->getPost("tat_category");
+
+ $data = array_values(array_filter($data, function($dat) use ($tat) {
+ return $dat['tat'] == $tat;
+ }));
+
+ }
// print_rr($data);
// log_message('error',' Claims Master Data '.json_encode($data));die();
// print_rr($data);die();
@@ -954,10 +975,27 @@ class TicketController extends BaseController
}
public function convertHtmlToText($html)
+ {
+ if(!empty($html)){
+ $dom = new DOMDocument();
+ @$dom->loadHTML($html);
+ return strip_tags($dom->saveHTML());
+ }else{
+ return '';
+ }
+ }
+
+ public function removeTicket()
{
- $dom = new DOMDocument();
- @$dom->loadHTML($html);
- return strip_tags($dom->saveHTML());
+ $ticket_id = $this->request->getGet('ticket_id');
+ if(!empty($ticket_id)){
+ $data['is_active'] = 0;
+ $this->ticketMasterModel->where('id', $ticket_id)->set($data)->update();
+ return $this->respond(['status' => true, 'code' => 200, 'message' => 'Claim removed successfully'], 200);
+ }else{
+ return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove Claim'], 200);
+ }
+
}
//---- Email Trigger Part----------------------------------------------------------------------------------------------
@@ -1051,6 +1089,10 @@ class TicketController extends BaseController
$this->myLogger->logme('error', "Replacing placeholders in content");
if (!empty($ticket_data) && !empty($content)) {
+ // print_rr($ticket_data);die();
+ if (!isset($ticket_data['id'])) { $ticket_data['id'] = $ticket_data['ticket_master_id'];}
+ if (!isset($ticket_data['ticket_master_id'])) {$ticket_data['ticket_master_id'] = $ticket_data['id'];}
+
foreach ($this->placeHolders as $key => $value) {
if ($value == "emp_code") {
@@ -1434,7 +1476,7 @@ class TicketController extends BaseController
'TPA_NAME', 'NON ID', 'ID NOT GENERATED', 'CDA', 'INFORMATION REQUIRED',
'UNDER PROCESS - CLAIM NO. UPDATION',
'UNDER PROCESS - QUERY DOCUMENT RECEIVED', 'APPROVED', 'PAYMENT INITIATED',
- 'TOTAL', 'SETTLED', 'CLOSED', 'CANCELLED', 'RETURNED', 'CLEARED_TOTAL'
+ 'TOTAL', 'SETTLED', 'CLOSED', 'CANCELLED', 'RETURNED', 'CLEARED_TOTAL','TPA_ID'
];
// Reorder data based on column order
@@ -1448,6 +1490,7 @@ class TicketController extends BaseController
$ordered_data[] = $temp;
}
$viewData['tpa_wise_data'] = $ordered_data;
+ // print_r($ordered_data);die();
// $html = view('claims_report_tpa_wise', $viewData);
$html = view('claims_report_tpa_wise',$viewData);
@@ -1455,6 +1498,9 @@ class TicketController extends BaseController
} else if ($received_data['report_type'] == 'tat_band_wise') {
$viewData['data'] = $this->ticketMasterModel->getTATReport($policy_type, $fromDate, $toDate);
+ $viewData['policyType'] = $policy_type;
+ $viewData['fromDate'] = $fromDate;
+ $viewData['toDate'] = $toDate;
$html = view('tat_report_band_wise_list', $viewData);
return $this->respond(['status' => true, 'html' => $html], 200);
}
@@ -1859,9 +1905,10 @@ class TicketController extends BaseController
}
}
- private function isDate($value) {
+ private function isDate($value, $format = 'Y-m-d') {
// Check if the value is a valid date string (basic validation)
- return strtotime($value) !== false;
+ $date = \DateTime::createFromFormat($format, $value);
+ return $date && $date->format($format) === $value;
}
diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php
index d2e30828..67ffc9b1 100755
--- a/app/Helpers/excel_util_helper.php
+++ b/app/Helpers/excel_util_helper.php
@@ -2210,12 +2210,14 @@ if (!function_exists('generate_family_floater_key')) {
$relation = 'parent';
} else if (strtolower(trim($relationship)) === 'son' || strtolower(trim($relationship)) === 'daughter') {
$relation = 'child';
- } else if (strtolower(trim($relationship)) === 'father in Law' || strtolower(trim($relationship)) === 'mother in Law') {
+ }else if((strtolower(trim($relationship)) === 'father in Law' || strtolower(trim($relationship)) === 'mother in Law') || (strtolower(trim($relationship)) === 'father-in-Law' || strtolower(trim($relationship)) === 'mother-in-Law')){
$relation = 'parent_in_law';
} else if (strtolower(trim($relationship)) === 'spouse') {
$relation = 'spouse';
- } else {
+ } else if(strtolower(trim($relationship)) === 'self'){
$relation = 'self';
+ }else{
+ $relation = '';
}
return $relation;
diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php
index 33f504c0..0d4529c3 100755
--- a/app/Helpers/utility_helper.php
+++ b/app/Helpers/utility_helper.php
@@ -55,8 +55,8 @@ if (!function_exists('file_Upload')) {
function file_Upload($fileToUpload, $filepath)
{
if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) {
+ $fileToUpload->move($filepath);
$fileName = $fileToUpload->getName();
- $fileToUpload->move($filepath, $fileName);
return $fileName;
} else {
return "";
diff --git a/app/Models/BdsPlacementModel.php b/app/Models/BdsPlacementModel.php
new file mode 100644
index 00000000..2cd7c6f4
--- /dev/null
+++ b/app/Models/BdsPlacementModel.php
@@ -0,0 +1,93 @@
+db->table("bds_installment_payment_details bipd")
+ ->select("bipd.*, ct.client_name,ct.short_name, cb.branch_name, leads.salse_person_id,cp.policy_no")
+ ->join("policy_transaction pt", "pt.id = bipd.pt_id")
+ ->join("clients ct", "ct.id = pt.client_id")
+ ->join("client_branch cb", "cb.id = pt.client_branch_id")
+ ->join("leads", "leads.id = bipd.lead_id")
+ ->join("client_policy cp","cp.id = pt.client_policy_id")
+ ->where("bipd.is_active", 1)
+ ->where("bipd.payment_date", date('Y-m-d', strtotime('+15 days')));
+
+ $data = $builder->get()->getResultArray();
+
+ // Loop through to extract sales person details
+ foreach ($data as &$row) {
+ $sales_person_ids = json_decode($row['salse_person_id'], true);
+ $sales_person_id = $sales_person_ids[0] ?? null;
+
+ if ($sales_person_id) {
+ $user = $this->db->table('user_profiles')
+ ->select('email') // or whatever field
+ ->where('id', $sales_person_id)
+ ->get()
+ ->getRowArray();
+
+ $row['sales_person'] = $user['email'] ?? 'N/A';
+ } else {
+ $row['sales_person'] = 'Not Assigned';
+ }
+
+ $head = $this->db->table('user_profiles')
+ ->select('email') // or whatever field
+ ->where('role', 5)
+ ->where('is_active',1)
+ ->get()
+ ->getResultArray();
+
+
+ $row['heads'] = $head;
+
+ $admin = $this->db->table('user_profiles')
+ ->select('email')
+ ->where("is_active",1)
+ ->where("role",1)
+ ->get()
+ ->getResultArray();
+
+ $row['admins'] = $admin;
+
+ $buisenessTeam = $this->db->table("user_teams ut")
+ ->select("up.email")
+ ->join('user_profiles up','up.id = ut.user_id and up.is_active = 1')
+ ->where("ut.team_id",7)
+ ->where("ut.is_active",1)
+ ->get()
+ ->getResultArray();
+
+ $row['buisness_team'] = $buisenessTeam;
+
+
+ }
+
+
+ return $data;
+ }
+}
diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php
index 1404190e..b85dad62 100644
--- a/app/Models/TicketMasterModel.php
+++ b/app/Models/TicketMasterModel.php
@@ -335,159 +335,240 @@ class TicketMasterModel extends Model
// return $data;
// }
+ // public function getTATReport($ticket_type = null, $start_date = null, $end_date = null)
+ // {
+ // //set default last 3 months data date
+ // $fromDate = date('Y-m-d', strtotime('-90 days'));
+ // $toDate = date('Y-m-d 23:59:59');
+
+ // if (!empty($start_date) && !empty($end_date)) {
+ // $fromDate = change_date_format($start_date);
+ // $toDate = change_date_format($end_date);
+ // }
+ // $ticket_type_data_1 = "";
+ // $ticket_type_data_2 = "";
+ // if (!empty($ticket_type)) {
+ // $ticket_type_data_1 = "AND ticket_type = $ticket_type";
+ // $ticket_type_data_2 = "WHERE tm.ticket_type_id = $ticket_type";
+ // }
+
+ // // Fetch claim statuses from the `ticket_claim_status` table
+ // $statusQuery = " SELECT
+ // id, claim_status, ticket_type
+ // FROM ticket_claim_status
+ // Where is_active = 1
+ // $ticket_type_data_1
+ // ";
+ // $statusResult = $this->db->query($statusQuery)->getResultArray();
+ // // dd($statusResult);
+
+ // // Initialize dynamic query parts
+ // $dynamicSelect = '';
+
+ // // Loop through each claim status and generate the COALESCE and CASE statements for the SELECT
+ // foreach ($statusResult as $status) {
+
+ // $columnName = $status['claim_status']; // Default column name
+
+ // if (empty($ticket_type)) {
+ // // Append the insurance type prefix based on `ticket_type`
+ // switch ($status['ticket_type']) {
+ // case 1:
+ // $columnName = "GMC - {$status['claim_status']}";
+ // break;
+ // case 2:
+ // $columnName = "GPA - {$status['claim_status']}";
+ // break;
+ // case 3:
+ // $columnName = "EDLI - {$status['claim_status']}";
+ // break;
+ // case 4:
+ // $columnName = "GTLI - {$status['claim_status']}";
+ // break;
+ // }
+ // }
+
+ // $dynamicSelect .= "
+ // COALESCE(
+ // SUM(
+ // CASE
+ // WHEN subquery.status_id = {$status['id']} THEN 1
+ // ELSE 0
+ // END
+ // ),
+ // 0
+ // ) AS `$columnName`, ";
+ // }
+
+ // // Remove the trailing comma from the SELECT part
+ // $dynamicSelect = rtrim($dynamicSelect, ', ');
+ // // dd($dynamicSelect);
+
+
+ // // Construct the full SQL query
+ // $sql = "
+ // SELECT
+ // tc.TAT_Category,
+ // $dynamicSelect
+ // FROM
+ // (
+ // SELECT 'Above 20 Days' AS TAT_Category
+ // UNION ALL
+ // SELECT '13-20 Days'
+ // UNION ALL
+ // SELECT '7-12 Days'
+ // UNION ALL
+ // SELECT '0-6 Days'
+ // ) AS tc
+ // LEFT JOIN (
+ // SELECT
+ // tm.id AS ticket_id,
+ // latest_status.claim_status_id AS status_id,
+ // CASE
+ // WHEN DATEDIFF(CURDATE(), COALESCE(latest_status.change_date, tm.created_at)) BETWEEN 0 AND 6 THEN '0-6 Days'
+ // WHEN DATEDIFF(CURDATE(), COALESCE(latest_status.change_date, tm.created_at)) BETWEEN 7 AND 12 THEN '7-12 Days'
+ // WHEN DATEDIFF(CURDATE(), COALESCE(latest_status.change_date, tm.created_at)) BETWEEN 13 AND 20 THEN '13-20 Days'
+ // ELSE 'Above 20 Days'
+ // END AS TAT_Category
+ // FROM
+ // ticket_master tm
+ // LEFT JOIN (
+ // SELECT
+ // th.ticket_id,
+ // th.new_value AS claim_status_id,
+ // MAX(th.created_at) AS change_date
+ // FROM
+ // ticket_history th
+ // WHERE
+ // th.field_name = 'claim_status_id'
+ // AND th.is_active = 1
+ // GROUP BY
+ // th.ticket_id, th.new_value
+ // ) AS latest_status ON latest_status.ticket_id = tm.id
+ // WHERE tm.is_active = 1
+ // AND tm.created_at >= '$fromDate'
+ // AND tm.created_at <= '$toDate'
+ // " . (!empty($ticket_type) ? " AND tm.ticket_type_id = $ticket_type" : "") . "
+ // GROUP BY tm.id, latest_status.claim_status_id, latest_status.change_date, tm.created_at
+ // ) AS subquery ON tc.TAT_Category = subquery.TAT_Category
+ // GROUP BY
+ // tc.TAT_Category
+ // ORDER BY
+ // FIELD(
+ // tc.TAT_Category,
+ // 'Above 20 Days',
+ // '13-20 Days',
+ // '7-12 Days',
+ // '0-6 Days'
+ // );
+ // ";
+
+ // // Execute the query and return the result
+ // $data = $this->db->query($sql)->getResultArray();
+ // // dd($data);
+ // print_rr($data);die();
+ // // print_rr($this->db->getLastQuery()->getQuery()); die;
+
+ // return $data;
+ // }
public function getTATReport($ticket_type = null, $start_date = null, $end_date = null)
{
- //set default last 3 months data date
+ // Set default date range (last 90 days)
$fromDate = date('Y-m-d', strtotime('-90 days'));
$toDate = date('Y-m-d 23:59:59');
-
+
if (!empty($start_date) && !empty($end_date)) {
$fromDate = change_date_format($start_date);
$toDate = change_date_format($end_date);
}
- $ticket_type_data_1 = "";
- $ticket_type_data_2 = "";
+
+ // Get all active claim statuses
+ $statusQuery = $this->db->table('ticket_claim_status')
+ ->select('id, claim_status')
+ ->where('is_active', 1)
+ ->orderBy('id', 'ASC');
+
if (!empty($ticket_type)) {
- $ticket_type_data_1 = "AND ticket_type = $ticket_type";
- $ticket_type_data_2 = "WHERE tm.ticket_type_id = $ticket_type";
+ $statusQuery->where('ticket_type', $ticket_type);
}
-
- // Fetch claim statuses from the `ticket_claim_status` table
- $statusQuery = " SELECT
- id, claim_status, ticket_type
- FROM ticket_claim_status
- Where is_active = 1
- $ticket_type_data_1
- ";
- $statusResult = $this->db->query($statusQuery)->getResultArray();
- // dd($statusResult);
-
- // Initialize dynamic query parts
- $dynamicSelect = '';
-
- // Loop through each claim status and generate the COALESCE and CASE statements for the SELECT
- foreach ($statusResult as $status) {
-
- $columnName = $status['claim_status']; // Default column name
-
- if (empty($ticket_type)) {
- // Append the insurance type prefix based on `ticket_type`
- switch ($status['ticket_type']) {
- case 1:
- $columnName = "GMC - {$status['claim_status']}";
- break;
- case 2:
- $columnName = "GPA - {$status['claim_status']}";
- break;
- case 3:
- $columnName = "EDLI - {$status['claim_status']}";
- break;
- case 4:
- $columnName = "GTLI - {$status['claim_status']}";
- break;
+
+ $statusResult = $statusQuery->get()->getResultArray();
+
+ // Create a list of all TAT categories we want in the output
+ $tatCategories = [
+ 'Above 20 Days',
+ '13-20 Days',
+ '7-12 Days',
+ '0-6 Days'
+ ];
+
+ // Initialize the result array with all TAT categories
+ $result = [];
+ foreach ($tatCategories as $category) {
+ $row = ['TAT_Category' => $category];
+ foreach ($statusResult as $status) {
+ $row[$status['claim_status']] = 0;
+ }
+ $result[] = $row;
+ }
+
+ // Get the base query for ticket counts by status and TAT category
+ $query = $this->db->table('ticket_master tm')
+ ->select([
+ 'tcs.claim_status',
+ 'CASE
+ WHEN DATEDIFF(CURDATE(), COALESCE(
+ (SELECT MAX(th.created_at)
+ FROM ticket_history th
+ WHERE th.ticket_id = tm.id
+ AND th.field_name = "claim_status_id"
+ AND th.is_active = 1),
+ tm.created_at
+ )) BETWEEN 0 AND 6 THEN "0-6 Days"
+ WHEN DATEDIFF(CURDATE(), COALESCE(
+ (SELECT MAX(th.created_at)
+ FROM ticket_history th
+ WHERE th.ticket_id = tm.id
+ AND th.field_name = "claim_status_id"
+ AND th.is_active = 1),
+ tm.created_at
+ )) BETWEEN 7 AND 12 THEN "7-12 Days"
+ WHEN DATEDIFF(CURDATE(), COALESCE(
+ (SELECT MAX(th.created_at)
+ FROM ticket_history th
+ WHERE th.ticket_id = tm.id
+ AND th.field_name = "claim_status_id"
+ AND th.is_active = 1),
+ tm.created_at
+ )) BETWEEN 13 AND 20 THEN "13-20 Days"
+ ELSE "Above 20 Days"
+ END AS tat_category',
+ 'COUNT(*) AS count'
+ ])
+ ->join('ticket_claim_status tcs', 'tcs.id = tm.claim_status_id AND tcs.is_active = 1')
+ ->where('tm.is_active', 1)
+ ->where('tm.created_at >=', $fromDate)
+ ->where('tm.created_at <=', $toDate)
+ ->groupBy('tcs.claim_status, tat_category')
+ ->orderBy('FIELD(tat_category, "Above 20 Days", "13-20 Days", "7-12 Days", "0-6 Days")');
+
+ if (!empty($ticket_type)) {
+ $query->where('tm.ticket_type_id', $ticket_type);
+ }
+
+ $countResults = $query->get()->getResultArray();
+
+ // Populate the result array with actual counts
+ foreach ($countResults as $row) {
+ foreach ($result as &$categoryRow) {
+ if ($categoryRow['TAT_Category'] === $row['tat_category']) {
+ $categoryRow[$row['claim_status']] = (int)$row['count'];
+ break;
}
}
-
- $dynamicSelect .= "
- COALESCE(
- SUM(
- CASE
- WHEN subquery.status_id = {$status['id']} THEN 1
- ELSE 0
- END
- ),
- 0
- ) AS `$columnName`, ";
}
-
- // Remove the trailing comma from the SELECT part
- $dynamicSelect = rtrim($dynamicSelect, ', ');
- // dd($dynamicSelect);
-
-
- // Construct the full SQL query
- $sql = "
- SELECT
- tc.TAT_Category,
- $dynamicSelect
- FROM
- (
- SELECT 'Above 20 Days' AS TAT_Category
- UNION ALL
- SELECT '13-20 Days'
- UNION ALL
- SELECT '7-12 Days'
- UNION ALL
- SELECT '0-6 Days'
- ) AS tc
- LEFT JOIN (
-
- SELECT
- th.ticket_id,
- tcs.claim_status,
- tcs.id AS status_id,
- CASE
- WHEN DATEDIFF(
- th.created_at,
- COALESCE(
- (SELECT MIN(created_at) FROM ticket_history th2 WHERE th2.ticket_id = th.ticket_id),
- tm.created_at
- )
- ) BETWEEN 0 AND 6 THEN '0-6 Days'
- WHEN DATEDIFF(
- th.created_at,
- COALESCE(
- (SELECT MIN(created_at) FROM ticket_history th2 WHERE th2.ticket_id = th.ticket_id),
- tm.created_at
- )
- ) BETWEEN 7 AND 12 THEN '7-12 Days'
- WHEN DATEDIFF(
- th.created_at,
- COALESCE(
- (SELECT MIN(created_at) FROM ticket_history th2 WHERE th2.ticket_id = th.ticket_id),
- tm.created_at
- )
- ) BETWEEN 13 AND 20 THEN '13-20 Days'
- ELSE 'Above 20 Days'
- END AS TAT_Category
-
- FROM
- ticket_master tm
- JOIN ticket_history th ON tm.id = th.ticket_id
- JOIN ticket_claim_status tcs ON th.field_name = 'claim_status_id' AND th.new_value = tcs.id
- $ticket_type_data_2
- AND tm.created_at >= '$fromDate'
- AND tm.created_at <= '$toDate'
- AND tm.is_active = 1
- AND th.is_active = 1
- AND tcs.is_active = 1
-
- ) AS subquery ON tc.TAT_Category = subquery.TAT_Category
- GROUP BY
- tc.TAT_Category
- ORDER BY
- FIELD(
- tc.TAT_Category,
- 'Above 20 Days',
- '13-20 Days',
- '7-12 Days',
- '0-6 Days'
- );
- ";
-
- // Execute the query and return the result
- $data = $this->db->query($sql)->getResultArray();
- // print_rr($this->db->getLastQuery(), $data); die;
-
- // $tableData = [];
- // if (!empty($data)) {
- // // Extract table headers from the first row keys
- // $headers = array_keys($data[0]);
- // $tableData['headers'] = $headers;
- // $tableData['body'] = $data;
- // }
-
- return $data;
+
+ return $result;
}
public function tpaWiseReport($policy_type = null, $start_date = null, $end_date = null)
@@ -544,6 +625,7 @@ class TicketMasterModel extends Model
// Construct the final SQL query
$sql = "
SELECT
+ tpa.id as TPA_ID,
tpa.name AS TPA_NAME,
$dynamicSelect,
($dynamicTotal) AS TOTAL,
diff --git a/app/Views/claims_report_tpa_wise.php b/app/Views/claims_report_tpa_wise.php
index 0a3fc65a..d473d717 100644
--- a/app/Views/claims_report_tpa_wise.php
+++ b/app/Views/claims_report_tpa_wise.php
@@ -37,16 +37,18 @@