diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a3a3f7ec..bd9feb09 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -448,6 +448,8 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "PolicyTransactionController::createEndorsementPolicy"); $routes->get("list/(:any)", "PolicyTransactionController::getEndorsementDataForEdit/$1"); $routes->get("remove/(:any)", "PolicyTransactionController::removeCDMaster/$1"); + $routes->get("list2", "PolicyTransactionController::viewEndorsement2"); + $routes->get("list2/(:any)", "PolicyTransactionController::getEndorsementDataForEdit2/$1"); }); $routes->group("report", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 2708abc4..7e154d64 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -2078,6 +2078,100 @@ $this->loadLayout('policy_transaction_endorsement_list', $data); } + public function viewEndorsement2() + { + // echo '
';
+            // !dd($this->getEndorsementDataForEdit(17));
+            $bds_edit_pt_id = $this->request->getGet('pt_id') ?? null;
+            $data['tab_name'] = 'Endorsements';
+            $data['page_name'] = 'Endorsements';
+            $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance'];
+            $data['issuer_branch'] = $this->nhanceBranchModel->where('is_active', 1)->findAll();
+            $data['client_type'] = [1 => 'Group', 2 => 'Individual'];
+
+            $data['policy_status'] = [
+                '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',
+            ];
+
+            $data['invoice_status'] = [
+                'yet_to_generate' => 'Pending',
+                'generated' => 'Generated',
+                'send' => 'Sent',
+                'recived' => 'Payment Received',
+            ];
+
+            $data['action_type'] = [
+                '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',
+            ];
+
+            $data['date_type'] = [
+                'policy_issue_date' => 'Policy Issue Date',
+                'policy_start_date' => 'Policy Start Date',
+                '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($issuer) || $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['client'] = $this->clientModel->where('is_active', 1)->findAll();
+            $data['policy_types'] = $this->policyTypeModel->where('is_active', 1)->findAll();
+
+            $data['insurer'] = $this->insurerModel->where('is_active', 1)->findAll();
+            // $data['tpa']           = $this->tpaModel->where('is_active', 1)->findAll();
+            $data['insurer_branch']      = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames();
+            $data['tpa']           = $this->tpaBranchModel->getTpaBranchesWithTpaNames();
+            list($policyList, $policyListByClient) = $this->getPolicyForEndorsment();
+
+            $data['endorsementPolicies'] = $policyList;
+            $data['endorsementPolicyListByClient'] = $policyListByClient;
+
+            // dd($data);
+            // print_r($data['endorsementPolicies']);die();
+
+            $this->loadLayout('policy_transaction_endorsement_list_2', $data);
+        }
+
         public function createEndorsementPolicy()
         {
             $id = $this->request->getPost('id');
@@ -2515,6 +2609,220 @@
             }
         }
 
+        public function getEndorsementDataForEdit2($id)
+        {
+            $data = $this->policyTransactionModel
+                ->select('
+                            policy_transaction.*, 
+                            clients.short_name as client_short_name, 
+                            clients.client_type, 
+                            ( 
+                                select last_action_date
+                                from policy_transaction_status
+                                where policy_tran_id = policy_transaction.id
+                                and status = policy_transaction.status
+                                order by id desc
+                                limit 1
+
+                            ) as last_action_date
+                        ')
+                ->join('clients', 'clients.id = policy_transaction.client_id')
+                ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left')
+                ->where('policy_transaction.id', $id)
+                ->where('policy_transaction.is_active', 1)
+                ->orderBy('id', 'asc')
+                ->first();
+
+            $pt_id = null;   
+
+            if(!empty($data)){
+                $inception_data = $this->policyTransactionModel
+                        ->where('policy_no', $data['policy_no'])
+                        ->where('client_id', $data['client_id'])
+                        ->where('action_type', 'inception')
+                        ->first();
+                $pt_id = $inception_data['id'];
+            }    
+
+            if (!empty($data['policy_start_date'])) {
+                $data['policy_start_date'] =  change_date_format($data['policy_start_date'], 'Y-m-d', 'd/m/Y');
+            }
+
+            if (!empty($data['policy_end_date'])) {
+                $data['policy_end_date'] =  change_date_format($data['policy_end_date'], 'Y-m-d', 'd/m/Y');
+            }
+
+            if (!empty($data['data_received_date'])) {
+                $data['data_received_date'] =  change_date_format($data['data_received_date'], 'Y-m-d', 'd/m/Y');
+            }
+
+            if (!empty($data['policy_issue_date'])) {
+                $data['policy_issue_date'] =  change_date_format($data['policy_issue_date'], 'Y-m-d', 'd/m/Y');
+            }
+
+            if (!empty($data['endorse_eff_date'])) {
+                $data['endorse_eff_date'] =  change_date_format($data['endorse_eff_date'], 'Y-m-d', 'd/m/Y');
+            }
+
+            if (!empty($data['install_due_date'])) {
+                $data['install_due_date'] =  change_date_format($data['install_due_date'], 'Y-m-d', 'd/m/Y');
+            }
+
+            if (!empty($data['last_action_date'])) {
+                $data['last_action_date'] =  change_date_format($data['last_action_date'], 'Y-m-d', 'd/m/Y');
+            }
+
+            if (!empty($data['month'])) {
+                $data['month'] =  change_date_format($data['month'], 'Y-m-d', 'M/Y');
+            }
+
+            // print_r($data); die;
+
+            //get PT Co-Share Details
+            $data['pt_co_share_details'] = $this->PTCOShareDetailsModel
+
+                ->select("
+                            pt_co_share_details.*,
+                    
+                            (
+                                SELECT
+                                    COUNT(*)
+                                FROM
+                                    co_share_stmt_details
+                                WHERE
+                                    co_share_stmt_details.co_share_id = pt_co_share_details.id
+                                    AND co_share_stmt_details.is_active = 1
+                            ) AS record_count,
+        
+                                (
+                                    SELECT 
+                                        SUM(actual_bp_amt) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_bp_amount,
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_tp_amt) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_tp_amount,
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_tep_amt) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_tep_amount,
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_bp_per) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_bp_percentage,
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_tp_per) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_tp_percentage,
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_tep_per) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_tep_percentage,
+                                
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_bp_brokerage_amt) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_bp_brokerage_amount,
+                                
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_tp_brokerage_amt) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_tp_brokerage_amount,
+                                
+                                
+                                (
+                                    SELECT 
+                                        SUM(actual_tep_brokerage_amt) 
+                                    FROM 
+                                        co_share_stmt_details 
+                                    WHERE 
+                                        co_share_id = pt_co_share_details.id 
+                                        AND is_active = 1
+                                        
+                                ) AS actual_tep_brokerage_amount, 
+                                 
+                                DATE_FORMAT(pt_policy_issue_date, '%d/%m/%Y') AS pt_policy_issue_date
+        
+                        ")
+                ->where('pt_id', $id)
+                ->where('is_active', 1)
+                ->orderBy('id', 'asc')
+                ->findAll();
+
+            // print_r($data['endorse_eff_date']); die;
+
+            $pt_bp_amt = $this->PTCOShareDetailsModel
+                ->select('bp_amt, amount')
+                ->where('pt_id', $id)
+                ->where('co_share_type', 1)
+                ->where('is_active', 1)
+                ->first();
+
+            // dd(db_connect()->getLastQuery() ,$pt_bp_amt);
+            $data['base_cd_amount'] = $pt_bp_amt['amount'] ?? null;
+
+            if ($data) {
+                return $this->respond(['status' => true, 'data' => $data, 'pt_id' => $pt_id], 200);
+            } else {
+                return $this->respond(['status' => false], 200);
+            }
+        }
+
         //------------------------------------------------------------------------------------------------
 
         //file upload function 
diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php
index 68950c44..eb8bfea0 100755
--- a/app/Views/layout/header.php
+++ b/app/Views/layout/header.php
@@ -2047,6 +2047,12 @@
                                                      Policy 2
                                                 
                                             
+                                            
  • + + + Endorsement 2 + +
  • diff --git a/app/Views/policy_transaction_endorsement_form_2.php b/app/Views/policy_transaction_endorsement_form_2.php new file mode 100644 index 00000000..94180c52 --- /dev/null +++ b/app/Views/policy_transaction_endorsement_form_2.php @@ -0,0 +1,2995 @@ + + + + + + + + + + + diff --git a/app/Views/policy_transaction_endorsement_list_2.php b/app/Views/policy_transaction_endorsement_list_2.php new file mode 100644 index 00000000..60e37342 --- /dev/null +++ b/app/Views/policy_transaction_endorsement_list_2.php @@ -0,0 +1,1036 @@ + + + + +
    +
    +
    +
    +
    +

    + Filter + + + +

    +
    +
    +
    +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    + +
    + +
    + + +
    + +
    + + +
    + + + +
    + + + +
    +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + $row) { ?> + + + + + + + + + + + + + + + + + + +
    SnoIssuerClientBranchInsurerPolicyEndorsement TypeEndorsement NoData Recived DateNo of InsuredNo of DependencePolicy Issue DateStatusAction
    + +
    +
    +
    +
    +
    + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/policy_transaction_inception_form_2.php b/app/Views/policy_transaction_inception_form_2.php index a1db7f44..edbfa453 100644 --- a/app/Views/policy_transaction_inception_form_2.php +++ b/app/Views/policy_transaction_inception_form_2.php @@ -718,10 +718,9 @@ -->
    - - + +
    -
    @@ -1831,11 +1830,6 @@ // $('#cd_ac_no_for_edit').val(res.data.cd_ac_no); $('#cd_ac_pk_for_leader').val(res.data.cd_ac_pk); - - // $('#entity_type_id').val(res.data.entity_type_id); - // getKYCEntityDocument(res.data.entity_type_id, res.data.client_id); - // appendKycTableListData(res.data.client_kyc); - // please don't forgot this ==> look at here please don't don't forgot $('#docs_type_id').empty(); // ✅ clear old options @@ -1843,133 +1837,6 @@ $('#tbody').empty(); $('#tbody').append(res.data.client_kyc_single_table); - - // let tbody = $('#tbody'); - // tbody.empty(); // ✅ Always clear first - - // let ckdlist = res.data.client_kyc_document_list; - - // if (!ckdlist || ckdlist.length === 0) { - - // // ✅ Show single merged row when no data - // let emptyRow = ` - // - // - // No data found - // - // - // `; - - // tbody.append(emptyRow); - // // return; // ✅ Stop further execution - // } - // else{ - // $.each(ckdlist, function (index, value) { - - // let sno = index + 1; - - // // ✅ If kyc_doc_type_id is null → use other_docs_name - // let docName = (value.kyc_doc_type_id === null || value.kyc_doc_type_id === '') - // ? value.other_docs_name - // : value.kyc_doc_type_id; - - // let fileName = value.file_name ? value.file_name : '-'; - - // let downloadBtn = ` - // - // - // `; - - // // Inside your $.each(list, function (index, value) { ... }) loop - // let editBtn = ` - // `; - - // // The edit UI block to be toggled - // let editUI = ` - // - // - //
    - // - // - // - - //
    - - //
    - // - // - //
    - - //
    - // - //
    - - //
    - // - //
    - - //
    - - //
    - // - // - // `; - - - - // let deleteBtn = ` - // - // `; - - // let row = ` - // ${sno} - // ${value.ui_docs_name} - // ${fileName} - // - // ${downloadBtn} - // ${editBtn} - // ${deleteBtn} - // - // - // ${editUI} `; - - // tbody.append(row); - // }); - // } - // // docs_type_id - // // res.data.client_kyc_dd_data // Setting values to correct fields $('#policy_tranction_primarykey').val(res.data.id); @@ -2045,6 +1912,18 @@ setTimeout(function() { // populateTable(res.data.pt_co_share_details, res.data.cd_ac_pk); populateCards(res.data.pt_co_share_details, res.data.cd_ac_pk); + let s = res.data.policy_start_date.split('/'); // ["DD","MM","YYYY"] + let e = res.data.policy_end_date.split('/'); // ["DD","MM","YYYY"] + + let start = new Date(s[2], s[1] - 1, s[0]); // YYYY, MM-1, DD + let end = new Date(e[2], e[1] - 1, e[0]); + let months = (end.getFullYear() - start.getFullYear()) * 12 + (end.getMonth() - start.getMonth()); + if (end.getDate() >= start.getDate()) { months += 1; } + let yearDiff = Math.ceil(months / 12); + // let yearDiff = (parseInt(e[2]) - parseInt(s[2])) + 1; + console.log("yearDiff =", yearDiff); + if (yearDiff > 1) { updateInsurerTitles(yearDiff); } + }, 1000); } @@ -3657,6 +3536,17 @@ co_share_type.forEach((value, index) => { formData.append(`co_share_type[${index}]`, value); }); + + let bp = document.getElementById("base_premium").value; + let tp = document.getElementById("tp_premium").value; + let ter = document.getElementById("ter_premium").value; + + for (let i = 0; i < insurerCount; i++) { + formData.append(`base_premium[${i}]`, bp); + formData.append(`tp_premium[${i}]`, tp); + formData.append(`ter_premium[${i}]`, ter); + } + //covert date to mysql format // alert(formData.get('policy_issue_date')); @@ -4427,7 +4317,7 @@ let cardHTML = `
    -
    Insurer - ${insurerCount}
    +
    Insurer - ${insurerCount}
    ${showAdd} @@ -4492,7 +4382,7 @@
    - +
    @@ -4774,6 +4664,9 @@
    `; $('#allInsurerCards').append(cardHTML); + setBPValue($('#base_premium').val()); + setTEPValue($('#ter_premium').val()); + setTPValue($('#tp_premium').val()); $('#follow_insurer_id_' + insurerCount).select2(); @@ -4891,8 +4784,27 @@ } console.log("UpdatedCa:", insurerCount); + updateInsurerTitles(yearDiff); } + function updateInsurerTitles(yearDiff) { + + $(".insurer-card-title").each(function (index) { + let cardIndex = index + 1; + + // Base title: Insurer - X + let title = `Insurer - ${cardIndex}`; + + // Add "(Year X)" only for the first yearDiff cards + if (cardIndex <= yearDiff) { + title += ` (Year ${cardIndex})`; + } + + $(this).text(title); + }); + } + + function resetInsurerCards() { @@ -6714,9 +6626,11 @@ } function setBPValue(inputValue) { - const bpValueField = document.querySelector('.bp_value'); - if (bpValueField) { - bpValueField.value = inputValue; + let bpValueField = document.querySelectorAll('.bp_value'); + + if(bpValueField){ + bpValueField.forEach((field) => { field.value = inputValue; }); + console.log("Updated", bpValueField.length, "hidden base premiums"); } else { console.error("Error: Element with class '.bp_value' not found."); } @@ -6724,9 +6638,11 @@ } function setTPValue(inputValue) { - const tpValueField = document.querySelector('.tp_value'); + let tpValueField = document.querySelectorAll('.tp_value'); + if (tpValueField) { - tpValueField.value = inputValue; + tpValueField.forEach((field) => { field.value = inputValue; }); + console.log("Updated", tpValueFields.length, "hidden tp premiums"); } else { console.error("Error: Element with class '.tp_value' not found."); } @@ -6734,9 +6650,11 @@ } function setTEPValue(inputValue) { - const tepValueField = document.querySelector('.tep_value'); + let tepValueField = document.querySelectorAll('.ter_value'); + tepValueField.forEach((field) => { field.value = inputValue; }); if (tepValueField) { tepValueField.value = inputValue; + console.log("Updated", tepValueField.length, "hidden tep premiums"); } else { console.error("Error: Element with class '.tep_value' not found."); }