From 9f933095b04c744061b47e8d10affd64f5a912e1 Mon Sep 17 00:00:00 2001 From: velz Date: Thu, 19 Sep 2024 09:25:22 +0530 Subject: [PATCH 1/2] FEAT_INS_STATEMENT_UPLOAD_INV_PAYMENTS --- app/Config/Routes.php | 7 + .../PolicyTransactionController.php | 448 ++++++++++- app/Helpers/utility_helper.php | 4 +- app/Models/InsurerStatements.php | 30 + app/Models/InvPaymentDetailsModel.php | 24 + app/Models/PTCOShareDetailsModel.php | 41 + app/Views/insurer_statement_list.php | 708 ++++++++++++++++++ app/Views/layout/footer.php | 2 +- app/Views/layout/header.php | 3 + .../sample_excel/insurer_stament_sample.xlsx | Bin 0 -> 6594 bytes 10 files changed, 1264 insertions(+), 3 deletions(-) create mode 100644 app/Models/InsurerStatements.php create mode 100644 app/Models/InvPaymentDetailsModel.php create mode 100644 app/Views/insurer_statement_list.php create mode 100644 public/sample_excel/insurer_stament_sample.xlsx diff --git a/app/Config/Routes.php b/app/Config/Routes.php index eab9f909..6a7ac292 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -317,6 +317,13 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { $routes->get("list", "PolicyTransactionController::reportBDS"); }); + $routes->group("statement", ["filter" => "authMVC"], function ($routes) { + $routes->get("list", "PolicyTransactionController::statementList"); + $routes->post("upload", "PolicyTransactionController::uploadInsurerStatement"); + $routes->get("getPaymentDetails/(:any)", "PolicyTransactionController::getInvoicePaymentDetails/$1"); + $routes->post("saveInvoicePaymentDetails", "PolicyTransactionController::saveInvoicePaymentDetails"); + }); + }); $routes->cli('cli/processjob', 'JobWorker::processJob'); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 7c9c46e7..60daeb55 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -25,7 +25,9 @@ use App\Models\EmployeeModel; use App\Models\UserTeamsModel; use App\Models\UserModel; use App\Models\EmployeePolicyModel; - +use App\Models\InsurerStatements; +use App\Models\InvPaymentDetailsModel; +use Kint; class PolicyTransactionController extends BaseController { @@ -51,6 +53,9 @@ class PolicyTransactionController extends BaseController protected $userTeamsModel; protected $userModel; protected $employeePolicyModel; + protected $insurerStatements; + protected $invoiceStatus; + protected $invPaymentDetailsModel; public function __construct() { @@ -76,6 +81,15 @@ class PolicyTransactionController extends BaseController $this->userTeamsModel = new UserTeamsModel(); $this->userModel = new UserModel(); $this->employeePolicyModel = new EmployeePolicyModel(); + $this->insurerStatements = new InsurerStatements(); + $this->invPaymentDetailsModel = new InvPaymentDetailsModel(); + $this->invoiceStatus = [ + 'pending' => 'Pending', + 'generated' => 'Generated', + 'sent' => 'Sent', + 'payment_received' => 'Payment Received', + + ]; } // Policy Transaction Inception @@ -965,6 +979,438 @@ class PolicyTransactionController extends BaseController $this->loadLayout('report_bds_filter', $data); } + + //insurer statement list page + public function statementList() + { + // dd($this->updateInsurerStatement(['file_id' => 13])); + // $data['insurers'] = $this->insurerModel->where('is_active',1)->findAll(); + $data['invoice_status_array'] = $this->invoiceStatus; + $data['insurers'] = $this->insurerBranchModel ->getInsurerBranchesWithInsurerNames(); + + // dd( $data['insurers']); + $data['insurer_statement_list'] = $this->insurerStatements + ->select('insurer_statements.*, + insurers.name AS insurer_name,insurers.short_name,user_profiles.first_name,insurer_branch.branch_code + ') + ->join('insurers', 'insurer_statements.insurer_id = insurers.id') + ->join('insurer_branch', 'insurer_statements.branch_id = insurer_branch.id') + ->join('user_profiles', 'insurer_statements.created_by = user_profiles.id') + ->orderBy('insurer_statements.id', 'desc') + ->findAll(); + // dd( $data['insurer_statement_list']); + $this->loadLayout('insurer_statement_list', $data); + } + + public function uploadInsurerStatement() + { + + //validate uploaded file + $filename = ''; + $validated = $this->validate([ + 'statement' => [ + 'uploaded[statement]', + 'mime_in[statement,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]', + 'max_size[statement,16384]', + ], + ]); + $this->createStatementFolder(); + if ($validated) + { + $avatar = $this->request->getFile('statement'); + if (!$avatar) { + $this->myLogger->logme("error", 'Statement File not found'); + return $this->respond(['dataStatus' => false, 'code' => 400, 'message' => 'File not found'], 400); + } + + $is_moved = $avatar->move(WRITEPATH . 'uploads/statements/'); + if ($is_moved) { + $filename = $avatar->getName(); + // Handle successful upload, e.g., log success or further processing + $this->myLogger->logme("error", 'Statement File moved successful'); + + } else { + $this->myLogger->logme("error", 'Statement File move failed'); + return $this->respond(['dataStatus' => false, 'code' => 500, 'message' => 'File move failed'], 500); + } + } else { + $this->myLogger->logme("error", 'Statement Upload failed Invalid file'); + return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'Invalid file'], 404); + } + + //process post variable entry in file table + $loggedInUserID = get_session_userid(); + // dd($loggedInUserID); + // $loggedInUserID = 8; + + $insurer = $this->request->getPost('insurer'); + + $insurer_id = explode('-', $insurer)[0]; + $branch_id = explode('-', $insurer)[1]; + // print_r($insurer_id); + // print_r($branch_id); + // die(); + $month = $this->request->getPost('statement_month'); + $month = change_date_format($month,'Y-M-d','Y-m-d'); + // print_r($month);die; + + $file_id = $this->insurerStatements->insert(['insurer_id' => $insurer_id, 'branch_id' => $branch_id, 'file_name' => $filename,'month' => $month, 'created_by' => $loggedInUserID]); //here field policy_id have client_policy_id and not policy id from policy master + $this->myLogger->logme("error", '{file_id} statement uploaded success', ['file_id' => $file_id]); + + //validate file + $validation_result = $this->validateInsurerStatement(['file_id' => $file_id]); + //update file content to DB + if($validation_result['status'] ) + { + $this->updateInsurerStatement(['file_id' => $file_id]); + } + + if (!isset($file_id) || !$validation_result['status']) { + return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'file not uploaded', 'error_data' => $validation_result['error_data'],'error_code' => $validation_result['error_code']], 200); + } + + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => 'file upload success'], 200); + } + + public function createStatementFolder() + { + $folderPath = WRITEPATH . 'uploads/statements/'; + + // Check if the folder doesn't exist + if (!file_exists($folderPath)) + { + // Create the folder + if (mkdir($folderPath, 0777, true)) { + $this->myLogger->logme('error','statement upload folder created successfully'); + + // Set permissions to a+rwx (read, write, execute for all) + chmod($folderPath, 0777); + $this->myLogger->logme('error','Permissions set to a+rwx.'); + } else { + // echo "Failed to create folder."; + $this->myLogger->logme('error','Failed to create statement upload folder.'); + } + } + else + { + $this->myLogger->logme('error','upload folder exists.'); + } + } + + public function validateInsurerStatement($params) + { + //get file info + $file_id = $params['file_id']; + $file = $this->insurerStatements->find($file_id); + // dd($file); + $date = new \DateTime($file['month']); + + $month = $date->format('m'); + $year = $date->format('Y'); + + $error_data = ['error_code' => '','error_data' => []]; + $status = 'success'; + $ret_status = true; + // dd($month.'-'.$year); + $return = []; + if(!isset($file)) + { + //file not found in DB + return array('status' => false, 'msg' => 'statement file not found in DB'); + } + $file_name_with_path = WRITEPATH."/uploads/statements/".$file['file_name']; + + //check physical file + if(!file_exists($file_name_with_path)) + { + //file not found update status and reason + $message = "Physcial file not found"; + // echo $message; + $this->myLogger->logme('error',($message . ' for statement file id ' . $file_id)); + $this->insurerStatements->where('id', $file_id)->set(['file_status' => 'failed','reason' => json_encode(['error_code' => 0,'error_data' => $message])])->update(); + return array('status' => false, 'error_code' => 0); //0 - Physcial file not found + } + + //get excel data to php array + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + // dd($highestRowAndColumn); + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + unset($excel_data[0]); + // dd($excel_data); + //get no of line items and update in DB + $line_items = count($excel_data); + // get uploaded month transactions data + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); + // Kint::dump($source_data); + // Kint::dump($excel_data); + + // check policy no,insurer and etc in DB for this month + // if all good return true, otherwise return false with messssage + foreach ($excel_data as $excel_key => $excel_row) + { + $is_source_found = 0; + $excel_row[4] = trim($excel_row[4]); + $excel_row[5] = trim($excel_row[5]); + // Kint::dump(change_date_format($excel_row[4],'d-m-Y','Y-m-d')); + // echo $excel_row[1].'#'.$excel_row[2] .'#'.$excel_row[3].'#'.change_date_format($excel_row[4],'d-m-Y','Y-m-d').'#'.change_date_format($excel_row[5],'d-m-Y','Y-m-d').'
'; + foreach ($source_data as $source_key => $source_row) + { + // Kint::dump(change_date_format($excel_row[3],'d-m-Y','Y-m-d')); + if( (trim($excel_row[1]) == $source_row['policy_no']) && trim($excel_row[2]) == $source_row['endorsement_no'] && trim($excel_row[3]) == $source_row['client_name'] && change_date_format($excel_row[4],'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($excel_row[5],'d-m-Y','Y-m-d') == $source_row['policy_end_date']) + { + $is_source_found = 1; + unset($source_data[$source_key]); + continue 2; + } + } + + if($is_source_found == 0) + { + // echo $excel_key.'-'.$excel_row[1] . '- not found
'; + $error_data['error_code'] = 1;//match not found + // $error_data['error_data'] = ($error_data['error_data'] ?? []); + $error_data['error_data'] = array_merge($error_data['error_data'],[$excel_row[0]]);//match not found + } + } + + if($error_data['error_code']) + { + $status = 'failed'; + $ret_status = false; + } + //update in DB + $this->insurerStatements->where('id', $file_id)->set(['line_items' => $line_items,'file_status' => $status,'reason' => json_encode($error_data)])->update(); + return array('status' => $ret_status, 'error_code' => $error_data['error_code'],'error_data' => $error_data['error_data']); + } + + + public function updateInsurerStatement($params) + { + //get file info + $file_id = $params['file_id']; + $file = $this->insurerStatements->find($file_id); + // dd($file); + $date = new \DateTime($file['month']); + + $month = $date->format('m'); + $year = $date->format('Y'); + + $error_data = ['error_code' => '','error_data' => []]; + $status = 'success'; + $ret_status = true; + // dd($month.'-'.$year); + $return = []; + if(!isset($file)) + { + //file not found in DB + return array('status' => false, 'msg' => 'statement file not found in DB'); + } + $file_name_with_path = WRITEPATH."/uploads/statements/".$file['file_name']; + + //check physical file + if(!file_exists($file_name_with_path)) + { + //file not found update status and reason + $message = "Physcial file not found"; + // echo $message; + $this->myLogger->logme('error',($message . ' for statement file id ' . $file_id)); + $this->insurerStatements->where('id', $file_id)->set(['file_status' => 'failed','reason' => json_encode(['error_code' => 0,'error_data' => $message])])->update(); + return array('status' => false, 'error_code' => 0); //0 - Physcial file not found + } + + //get excel data to php array + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + // dd($highestRowAndColumn); + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + unset($excel_data[0]); + // dd($excel_data); + //get no of line items and update in DB + $line_items = count($excel_data); + // get uploaded month transactions data + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); + // Kint::dump($source_data);die; + // Kint::dump($excel_data); + + // check policy no,insurer and etc in DB for this month + // if all good return true, otherwise return false with messssage + $data_to_update = []; + foreach ($excel_data as $excel_key => $excel_row) + { + $is_source_found = 0; + $excel_row[4] = trim($excel_row[4]); + $excel_row[5] = trim($excel_row[5]); + + foreach ($source_data as $source_key => $source_row) + { + // Kint::dump(change_date_format($excel_row[3],'d-m-Y','Y-m-d')); + if( (trim($excel_row[1]) == $source_row['policy_no']) && trim($excel_row[2]) == $source_row['endorsement_no'] && trim($excel_row[3]) == $source_row['client_name'] && change_date_format($excel_row[4],'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($excel_row[5],'d-m-Y','Y-m-d') == $source_row['policy_end_date']) + { + $is_source_found = 1; + + //calculate percentage first + $total_amt = 0; + + $actual_bp_per = trim($excel_row[9]); + $actual_bp_brokerage = trim($excel_row[12]); + $actual_bp_amt = trim($excel_row[6]); + + 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 == "") + { + $actual_bp_per = round(($actual_bp_brokerage / $actual_bp_amt) * 100,2); + } + + } + else + { + $actual_bp_brokerage = $actual_bp_amt * ($actual_bp_per / 100); + $total_amt += $actual_bp_brokerage; + } + + $actual_tp_per = trim($excel_row[10]); + $actual_tp_brokerage = trim($excel_row[13]); + $actual_tp_amt = trim($excel_row[7]); + + 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 == "") + { + $actual_tp_per = ($actual_tp_brokerage / $actual_tp_amt) * 100; + } + } + else + { + $actual_tp_brokerage = $actual_tp_amt * ($actual_tp_per / 100); + $total_amt += $actual_tp_brokerage; + } + + $actual_tep_per = trim($excel_row[11]); + $actual_tep_brokerage = trim($excel_row[14]); + $actual_tep_amt = trim($excel_row[8]); + + 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 == "") + { + $actual_tep_per = ($actual_tep_brokerage / $actual_tep_amt) * 100; + } + } + else + { + $actual_tep_brokerage = $actual_tep_amt * ($actual_tep_per / 100); + $total_amt += $actual_tep_brokerage; + } + + //find variance + $variance_amt = $source_row['exp_amt'] - $total_amt; + + $data_to_update[] = ['id' => $source_row['id'],'actual_bp_amt' => $actual_bp_amt,'actual_tp_amt' => $actual_tp_amt,'actual_tep_amt' => $actual_tep_amt,'actual_bp_per' => $actual_bp_per,'actual_tp_per' => $actual_tp_per,'actual_tep_per' => $actual_tep_per,'variance' => $variance_amt,'actual_tep_brokerage_amt' => $actual_tep_brokerage,'actual_tp_brokerage_amt' => $actual_tp_brokerage,'actual_bp_brokerage_amt' => $actual_bp_brokerage,'reward' => trim($excel_row[15]),'statement_id' => $file_id]; + + unset($source_data[$source_key]); + continue 2; + } + } + } + $this->PTCOShareDetailsModel->updateBatch($data_to_update, 'id'); + // dd($data_to_update); + // if($error_data['error_code']) + // { + // $status = 'failed'; + // $ret_status = false; + // } + //update in DB + //$this->insurerStatements->where('id', $file_id)->set(['file_status' => $status,'reason' => json_encode($error_data)])->update(); + return array('status' => $ret_status, 'error_code' => $error_data['error_code'],'error_data' => $error_data['error_data']); + } + + public function getInvoicePaymentDetails() + { + $statement_id = $this->request->getUri()->getSegment(4); + + $inv_details = $this->insurerStatements->find($statement_id); + $inv_payment_details = $this->invPaymentDetailsModel + ->where('statement_id',$statement_id) + ->where('is_active',1) + ->get() + ->getResultArray(); + // print_r($inv_details); + $data = [ 'invoice_status' => $inv_details['invoice_status'], + 'invoice_no' => $inv_details['invoice_no'], + 'invoice_date' => $inv_details['invoice_date'] ]; + $data['payments'] = $inv_payment_details; + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $data], 200); + + + } + + public function saveInvoicePaymentDetails() + { + $jsonData = $this->request->getJSON(); + $jsonData = (array)$jsonData; + // echo 'Hi'; + // print_r($jsonData);die(); + + $invoiceStatus = $jsonData['invoice_status']; + $hiddenStatementId = $jsonData['hidden_statement_id']; + $invoiceNo = $jsonData['invoice_no']; + $invoiceDate = $jsonData['invoice_date']; + + //Update statement table + $parentData = [ + 'invoice_status' => $invoiceStatus, + 'invoice_no' => $invoiceNo, + 'invoice_date' => $invoiceDate, + 'updated_by' => get_session_userid() + ]; + + + + // $this->insurerStatements->update($hiddenStatementId, $parentData); + + // Process child data + $invoiceAmounts = $jsonData['invoice_amount']; + $utrNos = $jsonData['utr_no']; + $paymentDates = $jsonData['payment_date']; + $pks = $jsonData['pk']; + + foreach ($invoiceAmounts as $index => $invoiceAmount) { + $pk = $pks[$index]; // Get the pk for the current record + $utrNo = $utrNos[$index]; + $paymentDate = $paymentDates[$index]; + + // Prepare data for insert/update + $childData = [ + 'inv_amt' => $invoiceAmount, + 'utr_no' => $utrNo, + 'received_date' => $paymentDate, + 'statement_id' => $hiddenStatementId, + 'id' => is_numeric($pk) ? (int)$pk : '', + ]; + if($pk){ $childData['updated_by'] = get_session_userid(); } + else { $childData['created_by'] = get_session_userid(); } + // print_r($childData); + // Insert or update + $this->invPaymentDetailsModel->save($childData); + print_r($this->invPaymentDetailsModel->errors()); + + } + + return $this->respond(['dataStatus' => true, 'code' => 200], 200); + //return $this->response->setJSON(['dataStatus' => 'true']); + } } \ No newline at end of file diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 6c7c6c1a..a764697b 100644 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -24,6 +24,7 @@ if (!function_exists('change_date_format')) { function change_date_format($data, $source_format, $output_format) { + $data = trim($data); // echo $data, $source_format, $output_format;return true; try { // Create DateTime object with the source format @@ -31,7 +32,8 @@ if (!function_exists('change_date_format')) { // Check if the DateTime object is created successfully if ($dateTime === false) { - throw new Exception('Invalid date or format'); + $errors = DateTime::getLastErrors(); + throw new Exception('Invalid date or format' . implode(', ', $errors['errors'])); } // Format the DateTime object with the output format $formattedDate = $dateTime->format($output_format); diff --git a/app/Models/InsurerStatements.php b/app/Models/InsurerStatements.php new file mode 100644 index 00000000..6b85ed0f --- /dev/null +++ b/app/Models/InsurerStatements.php @@ -0,0 +1,30 @@ +db->table('pt_co_share_details pt_co') + ->select(' + pt_co.id, + pt_co.pt_id, + pt_co.exp_amt, + pt.id AS policy_transaction_id, + pt.endorsement_no, + c.client_name, + pt.created_at, + pt_co.insurer_id, + pt_co.insurer_branch_id, + pt.policy_no, + pt.policy_issue_date, + pt.policy_start_date, + pt.policy_end_date, + pt.status, + pt_co.bp_amt, + pt_co.tp_amt, + pt_co.tep_amt, + pt_co.exp_amt + ') + ->join('policy_transaction pt', 'pt_co.pt_id = pt.id') + ->join('clients c', 'pt.client_id = c.id') + ->where('pt_co.is_active', 1) + ->where('MONTH(pt.created_at)', $month) + ->where('YEAR(pt.created_at)', $year) + ->where('pt_co.insurer_id', $insurer_id) + ->where('pt_co.insurer_branch_id', $insurer_branch_id) + // ->where('pt_co.exp_amt', 0.00) + // ->orWhere('pt_co.exp_amt is null') + ->get() + ->getResultArray(); + } } diff --git a/app/Views/insurer_statement_list.php b/app/Views/insurer_statement_list.php new file mode 100644 index 00000000..29d14a7b --- /dev/null +++ b/app/Views/insurer_statement_list.php @@ -0,0 +1,708 @@ + + + + +
+
+
+
+
+
+

Insurer Statement List

+
+ + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Insurer
Month
Statement
Line Items
User/Time
Action
'.$row['first_name'] ?> + + +
+
+
+
+
+
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/layout/footer.php b/app/Views/layout/footer.php index 27e232ec..22f12861 100644 --- a/app/Views/layout/footer.php +++ b/app/Views/layout/footer.php @@ -299,7 +299,7 @@ fetchMessages(); - setInterval(fetchMessages, 10000); // Fetch messages every ten seconds + setInterval(fetchMessages, 60000); // Fetch messages every sixty seconds }); $(document).ready(function() { diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 03b42981..de039f2b 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -670,6 +670,9 @@
  • BDS
  • +
  • + Statement upload +
  • diff --git a/public/sample_excel/insurer_stament_sample.xlsx b/public/sample_excel/insurer_stament_sample.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..0cdabdf1cc8ce0b6f56d6c603e928a1058a38cde GIT binary patch literal 6594 zcmaKQ2UHVV*LINJLz7-YN4kJ?FMgRAUCf@R#^I4Py01Umg^0_CwqPDlkUhb->x&zQzh1P zp}a#vPwh)^dY)o9DM4N9STl>*3$20#gy>tp%#xRXbK1nxp_6HZP zp^F0%4|OQk_w;qg2-Y079RaFp4}7f5?p;20j9EomY$worJDV3xhZ40Q_3ygNc|y23 z?q8Kzyvdsi^6S^pdlFQp&_YiQjiv~|L4%t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N~V)W zGf@oRd4m+c?{3PS=+Zd8-#Ns=K!JCkggDPJpO0(dEg&od|JA$r@1 z^qTjLMB>EccM3g(r_B)-dEx;C+de97_L*Y@h!~BbYo!C6%Ry#Q>miYIl@gs0#N6tn zvB<((^UF&FT@|PrgPce-H^GZ~1uy1M#V0WyK0zXt?T1z!n~Q2{&zfuQx3lkh7P4cB zfP2V~e#UCDYZ59xQRLh8FOXy5TN}o+rrTYwRN0%ggliFzKD2_)rsW-SU!2o%37)M(MHAN|-$lN2 z`S+Iz;a~NK82qR6@7l<@4*1I~@tPst`IjpAr|a*W`&>NvWp?=C{qx@cM@soK%J0r_9Z{K?k;4DkEvf6l;u*%O+-NAM>f`!mAt>*6^}_+{7dD2pG+|KJRN#`zt% z&sWi3=8C`l1up-rseiivj#KC8{>y;)#QewoAFTh=`*$?>?>yS#v+^HrhyNhkp8%gy7Tll>f0Pug^sR?iZ literal 0 HcmV?d00001 From 78ab5918b0fd5be4338d1a0624e5a00d6605d38f Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 19 Sep 2024 15:54:53 +0530 Subject: [PATCH 2/2] FIX_POLICY_TRANCTION_ISSUE : RV --- .../PolicyTransactionController.php | 69 ++++++-- .../policy_transaction_endorsement_form.php | 125 +++++++------- .../policy_transaction_endorsement_list.php | 6 +- .../policy_transaction_inception_form.php | 154 ++++++++---------- .../policy_transaction_inception_list.php | 4 +- 5 files changed, 200 insertions(+), 158 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 7c9c46e7..6edf652e 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -75,7 +75,7 @@ class PolicyTransactionController extends BaseController $this->employeeModel = new EmployeeModel(); $this->userTeamsModel = new UserTeamsModel(); $this->userModel = new UserModel(); - $this->employeePolicyModel = new EmployeePolicyModel(); + $this->employeePolicyModel = new EmployeePolicyModel(); } // Policy Transaction Inception @@ -133,6 +133,7 @@ class PolicyTransactionController extends BaseController clients.client_name, client_branch.branch_name AS client_branch_name, insurers.name AS insurer_name, + insurers.short_name AS insurer_short_name, policy_type.policy_type, pt_co_share_details.agreed_amt AS amount, pt_co_share_details.bp_amt AS bp, @@ -141,7 +142,7 @@ class PolicyTransactionController extends BaseController ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left') ->join('clients', 'clients.id = policy_transaction.client_id', 'left') ->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left') - ->join('insurers', 'policy_transaction.insurer_id = insurers.id', 'left') + ->join('insurers', 'pt_co_share_details.insurer_id = insurers.id', 'left') ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') ->where('policy_transaction.is_active', 1) @@ -307,7 +308,6 @@ class PolicyTransactionController extends BaseController return $this->respondError("Failed to update policy transaction"); } - private function insertOrUpdateCoShareDetails($data, $pt_id) { // Prepare data for insertion and updating @@ -657,12 +657,14 @@ class PolicyTransactionController extends BaseController clients.short_name as client_short_name, clients.client_code, client_branch.branch_name as client_branch_name, - insurers.name as insurer_name, + insurers.name AS insurer_name, + insurers.short_name AS insurer_short_name, policy_type.policy_type ') + ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left') ->join('clients', 'policy_transaction.client_id = clients.id', 'left') ->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left') - ->join('insurers', 'policy_transaction.insurer_id = insurers.id','left') + ->join('insurers', 'pt_co_share_details.insurer_id = insurers.id','left') ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') ->where('policy_transaction.is_active', 1) @@ -682,7 +684,6 @@ class PolicyTransactionController extends BaseController $this->loadLayout('policy_transaction_endorsement_list', $data); } - public function createEndorsementPolicy() { $id = $this->request->getPost('id'); @@ -698,7 +699,7 @@ class PolicyTransactionController extends BaseController private function preparePolicyTransactionData() { $data = $this->request->getPost(); - // print_r($data); + // print_r($data); die; $data_received_date = (string)$this->request->getPost('data_received_date'); $closure_date = (string)$this->request->getPost('closure_date'); @@ -716,11 +717,57 @@ class PolicyTransactionController extends BaseController $issue_type = $this->policyTransactionModel ->where('action_type', 'inception') ->where('client_id', $this->request->getPost('client_id')) - ->where('client_branch_id', $this->request->getPost('client_branch_id')) + ->where('client_policy_id', $this->request->getPost('client_policy_id')) ->first(); + $data['tsi'] = generate_tsi_code($issue_type['issue_type'] ?? 1); - // print_r($data); die; + $client_branch_id = $data['client_branch_id']; + if($data['client_branch_id'] == ""){ + $client_branch_id = $issue_type['client_branch_id']; + } + + if(!$data['id']){ + $data += [ + 'issuer' => $issue_type['issuer'] ?? null, + 'client_type' => $data['client_type'] ?? $issue_type['client_type'] ?? null, + 'policy_type_id' => $issue_type['policy_type_id'] ?? null, + 'policy_type_id' => $issue_type['policy_type_id'] ?? null, + 'issue_type' => $issue_type['issue_type'] ?? null, + 'source_client_policy_id' => $issue_type['source_client_policy_id'] ?? null, + 'cd_ac_no' => $issue_type['issue_type'] ?? null, + 'policy_issue_date' => $issue_type['policy_issue_date'] ?? null, + 'policy_start_date' => $issue_type['policy_start_date'] ?? null, + 'policy_end_date' => $issue_type['policy_end_date'] ?? null, + 'revenue_type' => $issue_type['revenue_type'] ?? null, + 'co_share' => $issue_type['co_share'] ?? 0, + 'bro_payable_by' => $issue_type['bro_payable_by'] ?? 0, + 'installment' => $issue_type['installment'] ?? null, + 'installment_data' => $issue_type['installment_data'] ?? null, + 'location' => $issue_type['location'] ?? null, + 'links' => $issue_type['links'] ??null, + 'stage' => $issue_type['stage'] ?? null, + 'etat' => $issue_type['etat'] ?? null, + 'etat_band' => $issue_type['etat_band'] ?? null, + 'edate' => $issue_type['edate'] ?? null, + 'renewal_date' => $issue_type['renewal_date'] ?? null, + 'rollover_date' => $issue_type['rollover_date'] ?? null, + 'policy_holder_name' => $issue_type['policy_holder_name'] ?? null, + 'same_as_proposer' => $issue_type['same_as_proposer'] ?? 1, + 'ref' => $issue_type['ref'] ?? null, + 'spl' => $issue_type['spl'] ?? null, + 'fund_received' => $issue_type['fund_received'] ?? null, + 'listed_insurers' => $issue_type['listed_insurers'] ?? null, + 'ppteam' => $issue_type['ppteam'] ?? null, + 'sales_generated_by' => $issue_type['sales_generated_by'] ?? null, + 'serviced_by' => $issue_type['serviced_by'] ?? null + ]; + + $data['client_branch_id'] = $client_branch_id; + } + // print_r($issue_type); + // print_r($data); + // die; return $data; } @@ -730,11 +777,11 @@ class PolicyTransactionController extends BaseController $insert = $this->policyTransactionModel->insert($data); if ($insert) { + $this->insertTransactionStatus($insert, $data['status'], 1); $this->handleCompletedStatus($data, $insert); $this->insertOrUpdateCoShareDetails($data, $insert); - return $this->respond(['status' => true, 'message' => 'Endorsement transaction created successfully'], 200); } @@ -785,7 +832,6 @@ class PolicyTransactionController extends BaseController } } - public function getEndorsementDataForEdit($id) { $data = $this->policyTransactionModel @@ -894,6 +940,7 @@ class PolicyTransactionController extends BaseController ->join('policy_transaction', 'policy_transaction.id = pt_co_share_details.pt_id') ->where('policy_transaction.client_id', $client_id) ->where('policy_transaction.client_policy_id', $client_policy_id) + ->where('policy_transaction.action_type', 'inception') ->findAll(); if ($totalCount) { diff --git a/app/Views/policy_transaction_endorsement_form.php b/app/Views/policy_transaction_endorsement_form.php index 3b7b4ae0..8478f296 100644 --- a/app/Views/policy_transaction_endorsement_form.php +++ b/app/Views/policy_transaction_endorsement_form.php @@ -284,13 +284,15 @@ Premium Details + - + Insurer + - + Is Leader? @@ -630,6 +632,7 @@ $("#endorsement_form_id").submit(function(event) { if (res.status == true) { toastr.success(res.message, 'Success'); $('#policy_tranction_primarykey').val(res.pt_id); + window.location.reload(true); } else { toastr.error(res.message, 'Error'); } @@ -832,23 +835,23 @@ function addInsurerColumn() { switch(index) { case 0: // Insurer selection newCell = ` - - `; + + `; break; case 1: // Is Leader? newCell = ` - - + + `; break; case 2: // Co-Share % @@ -860,7 +863,7 @@ function addInsurerColumn() { case 4: // TP / Ter Premium newCell = ``; break; - case 5: // co Premium + case 5: // Co Premium newCell = ``; break; case 6: // CGST @@ -873,13 +876,13 @@ function addInsurerColumn() { newCell = ``; break; case 9: // GST Amount - newCell = ``; + newCell = ``; break; case 10: // Stamp Duty newCell = ``; break; case 11: // Total - newCell = ``; + newCell = ``; break; case 12: // Agreed BP % newCell = ``; @@ -888,69 +891,68 @@ function addInsurerColumn() { newCell = ``; break; case 14: // Agreed Amount - newCell = ``; + newCell = ``; break; case 15: // Standard BP % - newCell = ``; + newCell = ``; break; + case 16: // Standard TP % - newCell = ``; - newCell += ``; + newCell = ``; + newCell += ``; break; case 17: // id newCell = ``; break; - } + // Append new cell to the current row $(this).append(newCell); - $('#follow_insurer_id_' + insurerCount).select2() + // Initialize select2 for newly added insurer select dropdown + $('#follow_insurer_id_' + insurerCount).select2(); - var selectedOption = $('#policy_type_id').find('option:selected'); + // Get selected policy type data + const selectedOption = $('#policy_type_id').find('option:selected'); + const bap = selectedOption.data('bap'); - var ebp = selectedOption.data('ebp'); - var etp = selectedOption.data('etp'); - var etep = selectedOption.data('etep'); - var iep = selectedOption.data('iep'); - var itp = selectedOption.data('itp'); - var itep = selectedOption.data('itep'); - - var bap = selectedOption.data('bap'); - - - if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ - $('#tp_premium_td').text('Ter Premium') - $('#agree_tp_td').text('Agreed Ter %') - $('#std_head').text('Standard Ter %') - $('.std_ter_td').show() + // Update column headers and visibility based on policy type + if (bap === 'Fire' || bap === 'Marine Cargo' || bap === 'Marine Hull') { + $('#tp_premium_td').text('Ter Premium'); + $('#agree_tp_td').text('Agreed Ter %'); + $('#std_head').text('Standard Ter %'); + $('.std_ter_td').show(); $('.std_tp_td').hide(); - }else{ - $('#tp_premium_td').text('TP Premium') - $('#agree_tp_td').text('Agreed TP %') - $('#std_head').text('Standard TP %') - $('.std_ter_td').hide() - $('.std_tp_td').show() + } else { + $('#tp_premium_td').text('TP Premium'); + $('#agree_tp_td').text('Agreed TP %'); + $('#std_head').text('Standard TP %'); + $('.std_ter_td').hide(); + $('.std_tp_td').show(); } - if(bap == 'Motor'){ + // Hide TP premium row for Motor policy type + if (bap === 'Motor') { $('#tp_premium_tr').hide(); - }else{ + } else { $('#tp_premium_tr').show(); } - $('[name="standard_bp[]"]').val(ebp); - $('[name="standard_tp[]"]').val(etp); - $('[name="standard_tep[]"]').val(etep); + // Set standard values + $('#standard_bp_' + insurerCount).val(selectedOption.data('ebp')); + // $('[name="standard_bp[]"]').val(selectedOption.data('ebp')); + $('[name="standard_tp[]"]').val(selectedOption.data('etp')); + $('[name="standard_tep[]"]').val(selectedOption.data('etep')); - if(insurerCount > 1){ + // Set 'follow_insurer' to required if more than 1 column exists + if (insurerCount > 1) { $('.follow_insurer').prop('required', true); - }else{ + } else { $('.follow_insurer').prop('required', false); } - }); + // Add click event for delete button $('.delete-insurer').off('click').on('click', function() { const index = $(this).closest('th').index(); @@ -994,16 +996,18 @@ function removeAllColumnsExceptFirst(tableId) { function populateTable(dataArray, status = false) { dataArray.forEach((data, index) => { // Add a new insurer column for each entry in the data array - addInsurerColumn(); // This will add a new column dynamically + addInsurerColumn(); // Assuming this function adds a new column dynamically // Populate the fields with the provided data $('#insurerTable tbody tr').each(function(rowIndex, row) { - const cell = $(row).find('td').eq(insurerCount); // Get the newly added column by `insurerCount` + const cell = $(row).find('td').eq(insurerCount); // Ensure insurerCount is correctly set or incremented - let insurer = data.insurer_branch_id + '-' + data.insurer_id + // Split insurer id and branch id properly + let insurer = data.insurer_branch_id + '-' + data.insurer_id; + switch (rowIndex) { case 0: // Insurer selection - cell.find('select').val(insurer).change(); + cell.find('select').val(insurer).prop('disabled', true).select2(); break; case 1: // Is Leader? cell.find('input[type="checkbox"]').prop('checked', data.co_share_type === '1'); @@ -1058,11 +1062,12 @@ function populateTable(dataArray, status = false) { } break; case 17: // id - cell.find('input').val(data.id); + cell.find('input').val(status ? data.id : ''); break; } }); }); } + \ No newline at end of file diff --git a/app/Views/policy_transaction_endorsement_list.php b/app/Views/policy_transaction_endorsement_list.php index 96e08b7d..aea58180 100644 --- a/app/Views/policy_transaction_endorsement_list.php +++ b/app/Views/policy_transaction_endorsement_list.php @@ -68,6 +68,7 @@ table.dataTable thead th { Issuer Client Branch + Insurer Policy Endorsement Type Endorsement No @@ -83,11 +84,12 @@ table.dataTable thead th { - + + - + diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index 85d882af..f6fcdaa8 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -1123,54 +1123,57 @@ $(document).ready(function() { //edit function function getPolicyTransactionDataForEdit(input) { + $('.loader').fadeIn(); $('.loader-mask').fadeIn(); $('#inception_form_id')[0].reset(); var id = $(input).attr('data-id'); + console.log('Selected policy transaction ID:', id); $.ajax({ url: '' + id, type: "GET", dataType: 'json', success: function(res) { - console.log('getPolicyTransactionDataForEdit', res); if (res.status == true) { - hide_list_show_add() + hide_list_show_add(); - var page_title = 'Edit Policy' + (res.data.client_short_name || res.data.policy_type || res - .data.policy_no ? ' - ' + [res.data.client_short_name, res.data.policy_type, res - .data.policy_no - ].filter(Boolean).join('-') : ''); + var page_title = 'Edit Policy' + (res.data.client_short_name || res.data.policy_type || res.data.policy_no ? + ' - ' + [res.data.client_short_name, res.data.policy_type, res.data.policy_no] + .filter(Boolean).join('-') : ''); - $('#page_title').text(page_title) + $('#page_title').text(page_title); + // Setting values to correct fields $('#policy_tranction_primarykey').val(res.data.id); $('#client_policy_id').val(res.data.client_policy_id); $('#client_id_for_edit').val(res.data.client_id); $('#issuer').val(res.data.issuer); - $('#issue_type').val(res.data.issue_type).change(); + $('#issue_type').val(res.data.issue_type); - $('#client_id').val(res.data.client_id).change(); - $('#client_type').val(res.data.client_type); - $('#insurer_id').val(res.data.insurer_branch_id + '-' + res.data.insurer_id).change(); - $('#vehicle_no').val(res.data.vehicle_id).change(); + setTimeout(function() { + $('#client_id').val(res.data.client_id).change(); + $('#client_type').val(res.data.client_type); + $('#insurer_id').val(res.data.insurer_branch_id + '-' + res.data.insurer_id); + $('#vehicle_no').val(res.data.vehicle_id).select2(); + }, 1000); var tpaValue = ''; - if (res.data.master_tpa_branch_id && res.data.master_tpa_id) { tpaValue = res.data.master_tpa_branch_id + '-' + res.data.master_tpa_id; - }else if(res.data.tpa_branch_id && res.data.tpa_id){ + } else if (res.data.tpa_branch_id && res.data.tpa_id) { tpaValue = res.data.tpa_branch_id + '-' + res.data.tpa_id; } $('#tpa').val(tpaValue).change(); - if(res.data.master_policy_type_id){ + + if (res.data.master_policy_type_id) { $('#policy_type_id').val(res.data.master_policy_type_id).change(); - }else{ + } else { $('#policy_type_id').val(res.data.policy_type_id).change(); } @@ -1184,7 +1187,7 @@ function getPolicyTransactionDataForEdit(input) { appendFileTableBody(res.data.pt_files); - if(res.data.pt_co_share_details){ + if (res.data.pt_co_share_details) { populateTable(res.data.pt_co_share_details); } @@ -1193,29 +1196,24 @@ function getPolicyTransactionDataForEdit(input) { } if (res.data.pt_co_share_details && res.data.pt_co_share_details.length > 0) { - - $('#tab_content').empty() - count = 0 - + $('#tab_content').empty(); + count = 0; $.each(res.data.pt_co_share_details, function(index, item) { - // appendNewTab(item); + // appendNewTab(item); // Uncomment when implementing tab addition logic }); - } - setTimeout(function() { - $('#cd_ac_no').val(res.data.cd_ac_no); - $('#client_branch_id').val(res.data.client_branch_id).change(); + $('#client_branch_id').val(res.data.client_branch_id).select2(); $('#source_client_policy_id').val(res.data.source_client_policy_id).change(); $('#base_policy').val(res.data.base_policy).change(); $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); + }, 2000); - }, 1000) - + // Set additional fields $('#policy_status').val(res.data.status); $('#ref').val(res.data.ref); $('#spl').val(res.data.spl); @@ -1242,8 +1240,7 @@ function getPolicyTransactionDataForEdit(input) { $('#sales_generated_by').val(res.data.sales_generated_by ?? '').change(); $('#serviced_by').val(res.data.serviced_by ?? '').change(); - - // Issuer Type - JBIS or Nhance + // Additional form handling logic if (res.data.issue_type == 2) { $('#renewal').show(); $('#source_client_policy_id').attr('required', true); @@ -1252,106 +1249,95 @@ function getPolicyTransactionDataForEdit(input) { $('#source_client_policy_id').attr('required', false); } - //For Base Policy + // Handle base policy visibility if (res.data.is_addon == 2 || res.data.is_addon == 3) { $('#base_policy_id').show(); } else { $('#base_policy_id').hide(); } - //for Co Share Percentage + // Handle co-share percentage if (res.data.co_share == 1) { $('#cop_yes').prop('checked', true); - $('#add_more_row').removeClass('d-none'); - $('.payby').removeClass('d-none'); - $('#is_leader_tr').show() - $('#co_share_per_tr').show() - $('#co_premium_tr').show() + $('#add_more_row').removeClass('d-none'); + $('.payby').removeClass('d-none'); + $('#is_leader_tr').show(); + $('#co_share_per_tr').show(); + $('#co_premium_tr').show(); } else { $('#cop_yes').prop('checked', false); $('#add_more_row').addClass('d-none'); $('.payby').addClass('d-none'); - $('#is_leader_tr').hide() - $('#co_share_per_tr').hide() - $('#co_premium_tr').hide() + $('#is_leader_tr').hide(); + $('#co_share_per_tr').hide(); + $('#co_premium_tr').hide(); } - //for Same Insured Name + // Handle "Same Insured Name" if (res.data.same_as_proposer == 1) { $('#same_as_proposer').prop('checked', true); $('#dynamic-form-container-for-insured').empty(); $('#family_details').hide(); } else { $('#same_as_proposer').prop('checked', false); - if(res.data.client_type == 2 && res.data.policy_type_id != 8){ + if (res.data.client_type == 2 && res.data.policy_type_id != 8) { $('#family_details').show(); $.each(res.data.emp_data, function(index, emp) { - appendInsured(emp) + appendInsured(emp); }); - - }else{ + } else { $('#dynamic-form-container-for-insured').empty(); $('#family_details').hide(); } } - // for Brokerage Pay By + // Handle brokerage pay by if (res.data.bro_payable_by == 1) { $('#bro_payable_by').prop('checked', true); } else { $('#bro_payable_by').prop('checked', false); } - //for Policy Tranction Status - if(res.data.status == "completed"){ - - $('#sales_row').show() - $('#policy_no').prop('required', true) - $('#policy_issue_date').prop('required', true) - $('#policy_start_date').prop('required', true) - $('#policy_end_date').prop('required', true) - $('#tpa').prop('required', true) - $('#emp_count').prop('required', true) - $('#dependent_count').prop('required', true) - $('.follow_insurer').prop('required', true) - - }else{ - $('#sales_row').hide() - $('#policy_no').prop('required', false) - $('#policy_issue_date').prop('required', false) - $('#policy_start_date').prop('required', false) - $('#policy_end_date').prop('required', false) - $('#tpa').prop('required', false) - $('#emp_count').prop('required', false) - $('#dependent_count').prop('required', false) - $('.follow_insurer').prop('required', false) - + // Policy transaction status handling + if (res.data.status == "completed") { + $('#sales_row').show(); + $('#policy_no').prop('required', true); + $('#policy_issue_date').prop('required', true); + $('#policy_start_date').prop('required', true); + $('#policy_end_date').prop('required', true); + $('#tpa').prop('required', true); + $('#emp_count').prop('required', true); + $('#dependent_count').prop('required', true); + $('.follow_insurer').prop('required', true); + } else { + $('#sales_row').hide(); + $('#policy_no').prop('required', false); + $('#policy_issue_date').prop('required', false); + $('#policy_start_date').prop('required', false); + $('#policy_end_date').prop('required', false); + $('#tpa').prop('required', false); + $('#emp_count').prop('required', false); + $('#dependent_count').prop('required', false); + $('.follow_insurer').prop('required', false); } - //for Client Type Changes - if(res.data.client_type == 2){ - if(policy_type_id == 8){ + // Client type changes + if (res.data.client_type == 2) { + if (res.data.policy_type_id == 8) { $('#policyholdernamediv').hide(); - }else{ + } else { $('#policyholdernamediv').show(); } - - - $('.branchdiv').hide(); + $('.branchdiv').hide(); $('#client_branch_id').prop('required', false); - } else { $('#policyholdernamediv').hide(); - $('.branchdiv').show(); + $('.branchdiv').show(); $('#client_branch_id').prop('required', true); - - } - } else { console.log('No data found'); } - }, error: function(xhr, status, error) { $('.loader').fadeOut(); @@ -1715,7 +1701,7 @@ $("#vehicle_form").submit(function(event) { getClientAndBranchAndPolicy(); $('#client_type').val(res.owner_type); setTimeout(function(){ - appendVehicles(res.vehicles, res.vehicle_id) + appendVehicles(res.vehicles, res.vehicle_id); $('#client_id').val(res.owner_id).change(); if(res.owner_type == 1){ diff --git a/app/Views/policy_transaction_inception_list.php b/app/Views/policy_transaction_inception_list.php index a88a9325..84dbad89 100644 --- a/app/Views/policy_transaction_inception_list.php +++ b/app/Views/policy_transaction_inception_list.php @@ -130,6 +130,7 @@ table.dataTable tbody td {
    Issuing Type
    Client Type
    Client / Branch
    +
    Insurer
    Policy
    Policy No
    Policy Issue Date
    @@ -150,7 +151,8 @@ table.dataTable tbody td { - + +