diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0cd7f7fe..877ba46e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -396,6 +396,9 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->post('savePlacementDataAndValidateMemberDataFile', 'LeadsController::savePlacementDataAndValidateMemberDataFile'); $routes->get('checkMemberDataFileValidationStatus', 'LeadsController::checkMemberDataFileValidationStatus'); $routes->match(['get', 'post', 'delete'], 'nhanceBranchMaster', 'MasterController::nhanceBranchMaster'); + $routes->match(['get', 'post', 'delete'], 'vehicleTypeMaster', 'MasterController::vehicleTypeMaster'); + $routes->match(['get', 'post', 'delete'], 'rtoMaster', 'MasterController::rtoMaster'); + }); @@ -713,6 +716,7 @@ $routes->group('test', function($routes) { $routes->get('mapping_client_id_and_branch_id','TestingController::mapping_client_id_and_branch_id'); $routes->get('membervalidation', 'TestingController::membervalidation'); $routes->get('generateExcel', 'TestingController::generateExcel'); + $routes->get('logo_renaming','TestingController::logo_renaming'); }); $routes->cli('cli/testcli', 'TestingController::testcli'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index a625d914..b3ce68e4 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -4816,6 +4816,7 @@ class ClientController extends AdminController 'vehicle_no' => $data['vehicle_no'], 'type' => $data['type'], 'rc' => $data['rc'], + 'rto_id' => $data['rto_id'], 'branch_id' => $branch_insert, 'owner' => $client_insert, ]; @@ -4861,6 +4862,7 @@ class ClientController extends AdminController 'vehicle_no' => $data['vehicle_no'], 'type' => $data['type'], 'rc' => $data['rc'], + 'rto_id' => $data['rto_id'], 'branch_id' => $data['branch_id'] ?? null, 'owner' => $data['owner'], ]; diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index cde00cf7..19cde67b 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -36,6 +36,8 @@ use App\Models\InsurerExcelExportTemplateModel; use App\Models\NhanceBranchModel; use App\Models\SettingsModel; use App\Models\VehicleModel; +use App\Models\VehicleTypeModel; +use App\Models\RTOModel; use CodeIgniter\CLI\CLI; @@ -2022,15 +2024,19 @@ class MasterController extends AdminController dd($result); } + //---------------------------------------------------------------------------------------------------------- + public function nhanceBranchMaster() { $nhanceBranchModel = new NhanceBranchModel(); + $method = $this->request->getMethod(); + $data['tab_name'] = 'Nhance Branch'; + $data['page_name'] = 'Nhance Branchs'; - if ($this->request->is('post')) { + if ($method === 'post') { $id = $this->request->getPost('pk') ?? null; $data = $this->request->getPost(); - print_r($data); die; if (empty($id)) { $update_status = $nhanceBranchModel->insert($data); @@ -2054,7 +2060,7 @@ class MasterController extends AdminController ], 200); } - } elseif ($this->request->is('get')) { + } elseif ($method === 'get') { $id = $this->request->getGet('pk') ?? null; @@ -2070,7 +2076,7 @@ class MasterController extends AdminController $data = $nhanceBranchModel->where('is_active', 1)->findAll(); return $this->loadLayout('nhance_branch_list', ['data' => $data]); - } elseif ($this->request->is('delete')) { + } elseif ($method === 'delete') { $input = $this->request->getRawInput(); $id = $input['pk'] ?? null; @@ -2106,7 +2112,167 @@ class MasterController extends AdminController public function vehicleTypeMaster() { + $vehicleTypeModel = new VehicleTypeModel(); + $method = $this->request->getMethod(); + $data['tab_name'] = 'Vehicle Type'; + $data['page_name'] = 'Vehicle Types'; + if ($method === 'post') { + $id = $this->request->getPost('pk') ?? null; + $data = $this->request->getPost(); + + if (empty($id)) { + $update_status = $vehicleTypeModel->insert($data); + } else { + $update_status = $vehicleTypeModel->where('id', $id)->set($data)->update(); + } + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Vehicle Type Master updated successfully', + 'data' => $data + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to update', + 'data' => $data + ], 200); + } + + } elseif ($method === 'get') { + + $id = $this->request->getGet('pk') ?? null; + + if (!empty($id)) { + $data = $vehicleTypeModel->where('is_active', 1)->where('id', $id)->findAll(); + if (!empty($data)) { + return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200); + } else { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200); + } + } + + $data = $vehicleTypeModel->where('is_active', 1)->findAll(); + return $this->loadLayout('vehicle_type_master_list', ['data' => $data]); + + } elseif ($method === 'delete') { + + $input = $this->request->getRawInput(); + $id = $input['pk'] ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $vehicleTypeModel->where('id', $id)->set(['is_active' => 0])->update(); + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Data removed successfully', + 'pk' => $id + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to remove data', + 'pk' => $id + ], 200); + } + } + } + + public function rtoMaster() + { + $rtoModel = new RTOModel(); + $method = $this->request->getMethod(); + $data['tab_name'] = 'RTO'; + $data['page_name'] = 'RTO'; + + if ($method === 'post') { + + $id = $this->request->getPost('pk') ?? null; + $data = $this->request->getPost(); + + if (empty($id)) { + $update_status = $rtoModel->insert($data); + } else { + $update_status = $rtoModel->where('id', $id)->set($data)->update(); + } + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'RTO Master updated successfully', + 'data' => $data + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to update', + 'data' => $data + ], 200); + } + + } elseif ($method === 'get') { + + $id = $this->request->getGet('pk') ?? null; + + if (!empty($id)) { + $data = $rtoModel->where('is_active', 1)->where('id', $id)->findAll(); + if (!empty($data)) { + return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200); + } else { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200); + } + } + + $data = $rtoModel->where('is_active', 1)->findAll(); + return $this->loadLayout('rto_master_list', ['data' => $data]); + + } elseif ($method === 'delete') { + + $input = $this->request->getRawInput(); + $id = $input['pk'] ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $rtoModel->where('id', $id)->set(['is_active' => 0])->update(); + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Data removed successfully', + 'pk' => $id + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to remove data', + 'pk' => $id + ], 200); + } + } } } \ No newline at end of file diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 338b4c16..65c7db4f 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -151,6 +151,8 @@ class PolicyTransactionController extends BaseController // 'bicycle' => 'Bicycle' // ]; $data['vehicle_type'] = db_connect()->table('vehicle_type')->where('is_active', 1)->get()->getResultArray(); + $data['rto_details'] = db_connect()->table('rto_master')->where('is_active', 1)->get()->getResultArray(); + $data['vehicle_des'] = [ 'commercial' => 'Commercial', 'private' => 'Private', @@ -2122,7 +2124,7 @@ class PolicyTransactionController extends BaseController //insurer statement list page public function statementList() { - // dd($this->validateInsurerStatement(['file_id' => 49])); // for check validateInsurerStatementfunction with hard coded file id always un command + // dd($this->updateInsurerStatement(['file_id' => 133])); // for check validateInsurerStatementfunction with hard coded file id always un command $data['insurers'] = $this->insurerModel->where('is_active',1)->findAll(); $today = date('Y-m-d'); $fromday = $from_date = date('Y-m-d', strtotime('-180 days', strtotime($today))); @@ -2367,13 +2369,13 @@ class PolicyTransactionController extends BaseController // $excel_row = ExcelSanitizeHelper::sanitizeArrayData($excel_row); $is_source_found = 0; // Kint::dump($excel_key,$excel_row[1],$excel_row[2]); - $policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]); //policy_start_date from excel - $policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]); //policy_end_date from excel + // $policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]); //policy_start_date from excel + // $policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]); //policy_end_date from excel $policy_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[1]); //policy_end_date from excel $policy_no = preg_replace( '/[\x{200B}\x{200C}\x{200D}\x{FEFF}\x{00A0}\x{200E}\x{200F}\x{202A}-\x{202E}]/u', '', $excel_row[1]); //policy_end_date from excel - $client_name = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[3]); //clientname from excel + // $client_name = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[3]); //clientname from excel $endorsement_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[2]); //policy_end_date from excel $endorsement_no = preg_replace( '/[\x{200B}\x{200C}\x{200D}\x{FEFF}\x{00A0}\x{200E}\x{200F}\x{202A}-\x{202E}]/u', '', $excel_row[2]); //policy_end_date from excel @@ -2479,11 +2481,11 @@ class PolicyTransactionController extends BaseController if (!$is_row_empty) { $is_source_found = 0; - $policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]); //policy_start_date from excel - $policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]); //policy_end_date from excel + // $policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]); //policy_start_date from excel + // $policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]); //policy_end_date from excel $policy_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[1]); //policy_end_date from excel $policy_no = preg_replace('/[\x{200C}\x{200B}]/u', '', $excel_row[1]); // - $client_name = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[3]); //clientname from excel + // $client_name = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[3]); //clientname from excel $endorsement_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[2]); //policy_end_date from excel foreach ($source_data as $source_key => $source_row) { @@ -2496,9 +2498,10 @@ class PolicyTransactionController extends BaseController //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]); + // $actual_bp_per = trim($excel_row[9]); //commented becoz this filed removed tfrom excel file + $actual_bp_per = 0; //set default value 0 for maintaining existing code flow + $actual_bp_brokerage = trim($excel_row[5]); + $actual_bp_amt = trim($excel_row[3]); if (($actual_bp_brokerage && $actual_bp_brokerage != 0 && $actual_bp_brokerage != "")) { $total_amt += $actual_bp_brokerage; @@ -2511,9 +2514,10 @@ class PolicyTransactionController extends BaseController $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]); + // $actual_tp_per = trim($excel_row[10]);//commented becoz this filed removed tfrom excel file + $actual_tp_per = 0;//set default value 0 for maintaining existing code flow + $actual_tp_brokerage = trim($excel_row[6]); + $actual_tp_amt = trim($excel_row[4]); if ($actual_tp_brokerage && $actual_tp_brokerage != 0 && $actual_tp_brokerage != "") { $total_amt += $actual_tp_brokerage; @@ -2526,9 +2530,13 @@ class PolicyTransactionController extends BaseController $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]); + // $actual_tep_per = trim($excel_row[11]); + // $actual_tep_brokerage = trim($excel_row[14]); + // $actual_tep_amt = trim($excel_row[8]); + + $actual_tep_per = 0; + $actual_tep_brokerage = 0; + $actual_tep_amt = 0; if ($actual_tep_brokerage && $actual_tep_brokerage != 0 && $actual_tep_brokerage != "") { $total_amt += $actual_tep_brokerage; @@ -2544,7 +2552,7 @@ class PolicyTransactionController extends BaseController //find variance $variance_amt = $source_row['exp_amt'] - $total_amt; - $data_to_update[] = ['co_share_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]; + $data_to_update[] = ['co_share_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[7]), 'statement_id' => $file_id]; unset($source_data[$source_key]); continue 2; diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index d003037e..a7cdddd1 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -715,4 +715,97 @@ class TestingController extends BaseController ]; } + + public function logo_renaming(){ + + $directory = ROOTPATH . 'public/uploads/logo/'; + + if (!is_dir($directory)) { + die("Directory not found: $directory"); + } + + $files = scandir($directory); + + $client_logo_files = $this->get_client_logo_files(); + + $rename_files = ""; + $failed_rename_files = ""; + + foreach ($files as $file) { + // Skip system entries + if ($file === '.' || $file === '..' ) { + continue; + } + + + $oldPath = $directory . $file; + + if (is_file($oldPath) && in_array(trim($file) , $client_logo_files)) { + + // Remove all spaces from filename + $newFileName = preg_replace('/\s+|\x{00A0}|\x{200B}|\x{200C}|\x{200D}|\x{FEFF}/u', '', $file); + + $newPath = $directory . $newFileName; + + // Only rename if the name changed + if ($oldPath !== $newPath) { + if (rename($oldPath, $newPath)) { + $rename_files .= "\n Renamed: $file → $newFileName \n"; + } else { + $failed_rename_files .= "\n Failed file: $file \n"; + } + } + } + } + + $dbUpdated = $this->update_client_logo_files(); + + log_message('error', 'Renamed Files: ' . $rename_files); + log_message('error', 'Failed Renames: ' . $failed_rename_files); + log_message('error', 'Database Update Status: ' . ($dbUpdated ? 'Success' : 'No changes made')); + + return $this->response->setJSON(['status' => 'success', + 'message' => 'Logo renaming completed. kindly check backend logs for details', + 'data' => [ + 'renamed_files' => $rename_files, + 'failed_renames' => $failed_rename_files + ] + ])->setStatusCode(200); + } + + public function get_client_logo_files(){ + + $db = \Config\Database::connect(); + + $sql = "SELECT client_logo FROM clients WHERE client_logo IS NOT NULL AND TRIM(client_logo) <> '' "; + + $query = $db->query($sql); + + $results = $query->getResultArray() ?? []; + + $files = array_map(function($item) { + return trim($item['client_logo']); + }, $results); + + return $files; + } + + public function update_client_logo_files(){ + + $db = \Config\Database::connect(); + + $sql = "UPDATE clients + SET client_logo = REPLACE(REPLACE(REPLACE(client_logo, CHAR(160), ''), ' ', ''), '\t', '') + WHERE client_logo IS NOT NULL + AND TRIM(client_logo) <> '' + "; + + $query = $db->query($sql); + + return $db->affectedRows() > 0; + + + } + + } diff --git a/app/Models/RTOModel.php b/app/Models/RTOModel.php new file mode 100644 index 00000000..6f5abcab --- /dev/null +++ b/app/Models/RTOModel.php @@ -0,0 +1,57 @@ + Users +
  • + Nhance Branch +
  • +
  • + Vehicle Type +
  • +
  • + RTO +
  • diff --git a/app/Views/nhance_branch_list.php b/app/Views/nhance_branch_list.php index 97660071..f3655ec8 100644 --- a/app/Views/nhance_branch_list.php +++ b/app/Views/nhance_branch_list.php @@ -14,25 +14,43 @@ S.No. Branch Name + Action + $row) { ?> - +    + + + + No data available + + @@ -43,14 +61,15 @@ +
    + + +
    +
    { + generateShortName(); // only runs after 200ms pause + }, 200); // adjust debounce delay as needed + }); **/ // $("#vehicle_form_row_div").on("input change", "input, select, textarea", function () { // if ($("#client_type").val() === "") { @@ -6001,6 +6022,9 @@ // resultDiv.classList.add('show'); $('#vehicle_no_validation').val('1'); } + + // call here + autoFetchRtoName(input); } // Custom Parsley validator for vehicle format @@ -6147,6 +6171,14 @@
    `; $('#client_row_div').append(html); + $('#client_name').on('input', generateShortName); + /** $("#client_name").on("input change keyup", function() { + clearTimeout(shortNameTimer); // cancel previous call + shortNameTimer = setTimeout(() => { + generateShortName(); // only runs after 200ms pause + }, 200); // adjust debounce delay as needed + }); **/ + if(client_type == 1){ $('.group_client').show(); @@ -6176,6 +6208,52 @@ $("#client_type").focus(); // focus back to client_type } }); + + } + + + + function generateShortName() { + let clientInput = $("#client_name"); + let shortInput = $("#short_name"); + let newClientName = clientInput.val().trim(); + + console.log(`LN : NEW - ${newClientName}`); + if (newClientName.length == 0){ shortInput.val(''); return; } + + if (newClientName.length > 0) { + let shortName = newClientName.substring(0, 10).replace(/\s+/g, '').toUpperCase(); + makeUniqueShortName(shortName); + } + } + + + function makeUniqueShortName(baseName) { + let input = $("#short_name")[0]; // input element + checkDuplicateTableFieldValue("clients", "short_name", baseName, function(isDuplicate) { + if (isDuplicate) { + // Append sequence until unique + let counter = 1; + function tryNext() { + let padded = String(counter).padStart(3, '0'); // 001, 002, 003 + let newName = baseName + padded; + + checkDuplicateTableFieldValue("clients", "short_name", newName, function(exists) { + if (exists) { + counter++; + tryNext(); // keep checking + } else { + $("#short_name").val(newName); + validateInputForClient(input, "clients", "short_name"); + } + }); + } + tryNext(); + } else { + $("#short_name").val(baseName); + validateInputForClient(input, "clients", "short_name"); + } + }); } function validateInputForClient(input, table, field) { @@ -6277,5 +6355,32 @@ console.log("✅ total[] changed:", val); }); + function autoFetchRtoName(val) { + console.log(`i am here ${val}`); + val = val.toUpperCase().trim(); + + let stateCode = val.slice(0, 2); // 1st 2 here i am split the state code + let numberCode = val.slice(2, 4); // 2nd 2 here i am split the number code + + console.log(`Ln ST: ${stateCode} | NC: ${numberCode}`); + + let matched = false; + + $('#rto_id option').each(function() { + let optionState = $(this).attr('data-state'); + let optionCode = $(this).attr('data-code'); + console.log(`Ln optionState : ${optionState} | optionCode : ${optionCode}`); + + if (stateCode === optionState && numberCode === optionCode) { + $('#rto_id').val($(this).val()).trigger('change'); // ✅ select it + matched = true; + return false; // break the loop + } + }); + + if (!matched) { + $('#rto_id').val('').trigger('change'); // reset select + } + } diff --git a/app/Views/rto_master_list.php b/app/Views/rto_master_list.php new file mode 100644 index 00000000..2ec05a90 --- /dev/null +++ b/app/Views/rto_master_list.php @@ -0,0 +1,254 @@ + + + +
    +
    +
    +
    + + + + + + + + + + + + + + $row) { ?> + + + + + + + + + + + + + + + + +
    S.No.RTO Office atRTO CodeRTO StateAction
       + +
    No data available
    +
    +
    +
    +
    + + + + + + diff --git a/app/Views/vehicle_type_master_list.php b/app/Views/vehicle_type_master_list.php new file mode 100755 index 00000000..d8291b8a --- /dev/null +++ b/app/Views/vehicle_type_master_list.php @@ -0,0 +1,230 @@ + + + +
    +
    +
    +
    + + + + + + + + + + + + $row) { ?> + + + + + + + + + + + + + + +
    S.No.Vehicle TypeAction
       + +
    No data available
    +
    +
    +
    +
    + + + + + + diff --git a/public/sample_excel/insurer_stament_sample.xlsx b/public/sample_excel/insurer_stament_sample.xlsx index 0cdabdf1..2c01d7fe 100644 Binary files a/public/sample_excel/insurer_stament_sample.xlsx and b/public/sample_excel/insurer_stament_sample.xlsx differ diff --git a/public/sample_excel/insurer_stament_sample_old.xlsx b/public/sample_excel/insurer_stament_sample_old.xlsx new file mode 100644 index 00000000..0cdabdf1 Binary files /dev/null and b/public/sample_excel/insurer_stament_sample_old.xlsx differ