diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 37bfc199..74daba0b 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -4443,6 +4443,8 @@ class ClientController extends AdminController // } // } + // ------------- CLIENT AND VEHICLE ------------------------------------------------------------------------------------------------ + public function createClientWithMinimalData2() { $postData = $this->request->getPost(); @@ -4516,6 +4518,7 @@ class ClientController extends AdminController // print_r($postData); die; $client_type = $postData['client_type'] ?? null; + $client_insert = null; if($client_type == 2){ $client_data = [ @@ -4546,6 +4549,7 @@ class ClientController extends AdminController } // Additional logic for non-individual clients (client_type != 2) + $branch_insert = null; if ($client_type != 2) { $unit[] = $postData['short_name'] . '-' . 001; $branch_data = [ @@ -4568,11 +4572,24 @@ class ClientController extends AdminController } } + $clients = $this->clientModel + ->select("*, DATE_FORMAT(dob, '%d-%m-%Y') as dob") + ->where('is_active', 1) + ->findAll(); + + // Fetch branches in a single query + $branches = $this->clientBranchModel + ->where('client_id', $client_insert) + ->where('is_active', 1) + ->findAll(); + return $this->respond([ 'status' => true, 'data' => $postData, 'client_id' => $client_insert, 'branch_id' => $branch_insert ?? null, + 'clients' => $clients, + 'branches' => $branches, 'message' => 'Client created successfully' ], 200); } @@ -4625,8 +4642,9 @@ class ClientController extends AdminController // print_r($data); die; if (isset($data['client_name']) && !empty($data['client_name'])) { - $client_type = $postData['client_type'] ?? null; + $client_type = $data['client_type'] ?? null; + $client_insert = null; if ($client_type == 2) { $client_data = [ @@ -4638,6 +4656,7 @@ class ClientController extends AdminController ]; $client_insert = $this->clientModel->insert($client_data); + } else if ($client_type == 1) { $client_data = [ @@ -4652,6 +4671,7 @@ class ClientController extends AdminController } // Additional logic for non-individual clients (client_type != 2) + $branch_insert = null; if ($client_type != 2) { $unit[] = $data['short_name'] . '-' . 001; $branch_data = [ @@ -4678,7 +4698,7 @@ class ClientController extends AdminController 'vehicle_no' => $data['vehicle_no'], 'type' => $data['type'], 'rc' => $data['rc'], - 'branch_id' => $data['branch_id'] ?? null, + 'branch_id' => $branch_insert, 'owner' => $client_insert, ]; @@ -4688,22 +4708,37 @@ class ClientController extends AdminController // $vehicles = $this->vehicleModel->where('is_active', 1)->findAll(); $vehicles = $this->vehicleModel->select('vehicle.*, clients.client_type') - ->join('clients', 'clients.id=vehicle.owner') + ->join('clients', 'clients.id = vehicle.owner') ->where('vehicle.is_active', 1) ->findAll(); + $clients = $this->clientModel + ->select("*, DATE_FORMAT(dob, '%d-%m-%Y') as dob") + ->where('is_active', 1) + ->findAll(); + + // Fetch branches in a single query + $branches = $this->clientBranchModel + ->where('client_id', $client_insert) + ->where('is_active', 1) + ->findAll(); + return $this->respond([ 'status' => true, 'vehicle_id' => $vehicle_insert, - 'owner_id' => $data['owner'], - 'owner_branch_id' => $data['branch_id'] ?? null, - 'owner_type' => $data['Owner_type'], + 'client_id' => $client_insert, + 'branch_id' => $branch_insert, + 'data' => $data, + 'clients' => $clients, + 'branches' => $branches, 'vehicles' => $vehicles, 'message' => 'Vehicle created successfully' ], 200); + } else { return $this->respond(['status' => false, 'message' => 'Failed to created vehicle'], 200); } + } else if (isset($data['owner']) && !empty($data['owner'])) { $vehicle_data = [ @@ -4715,13 +4750,34 @@ class ClientController extends AdminController ]; $vehicle_insert = $this->vehicleModel->insert($vehicle_data); + + $vehicles = $this->vehicleModel->select('vehicle.*, clients.client_type') + ->join('clients', 'clients.id = vehicle.owner') + ->where('vehicle.is_active', 1) + ->findAll(); + + $clients = $this->clientModel + ->select("*, DATE_FORMAT(dob, '%d-%m-%Y') as dob") + ->where('is_active', 1) + ->findAll(); + + // Fetch branches in a single query + $branches = $this->clientBranchModel + ->where('client_id', $data['owner']) + ->where('is_active', 1) + ->findAll(); if ($vehicle_insert) { return $this->respond([ 'status' => true, 'vehicle_id' => $vehicle_insert, + 'client_id' => $data['owner'], + 'branch_id' => $data['branch_id'], 'data' => $data, + 'clients' => $clients, + 'branches' => $branches, + 'vehicles' => $vehicles, 'message' => 'Vehicle created successfully' ], 200); @@ -4769,6 +4825,9 @@ class ClientController extends AdminController } } + // ------------- CLIENT AND VEHICLE ------------------------------------------------------------------------------------------------ + + public function getPolicyDetailsByPolicyId($id) { $policies = $this->clientPolicyModel diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 4622c86b..a8b1e7f2 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -134,12 +134,25 @@ class EmployeeRestController extends AdminController $client_branch_id = $this->request->getGet('client_branch_id'); if ($emp_code) { $relationship = 'self'; - $employee = $this->employeeModel->where('emp_code', $emp_code) - ->where('client_id', $client_id) - ->where('client_branch_id', $client_branch_id) - ->where('is_active', 1 ) - ->where('relationship', $relationship) - ->first(); + // $employee = $this->employeeModel->where('emp_code', $emp_code) + // ->where('client_id', $client_id) + // ->where('client_branch_id', $client_branch_id) + // ->where('is_active', 1 ) + // ->where('relationship', $relationship) + // ->first(); + $employee = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.emp_code', $emp_code) + ->where('employees.client_id', $client_id) + ->where('employees.client_branch_id', $client_branch_id) + ->where('employees.is_active', 1 ) + ->where('employees.relationship', $relationship) + ->where('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->where('employees.emp_status', ['active']) + ->first(); + if (null !== $this->request->getGet('client_policy_id')) { $date_coverage = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$this->request->getGet('client_policy_id'))->get()->getRow()->date_coverage; diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index ff28eceb..ac0d0c5e 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -226,7 +226,7 @@ -
+
@@ -1353,6 +1353,10 @@ $(document).ready(function(){ var client_id = selectedOption.data('cid'); var branch_id = selectedOption.data('bid'); var client_type = selectedOption.data('cty'); + $('#vehicle_row_div').empty(); + $('#client_row_div').empty(); + $('#actcual_clients').show(); + console.log(client_id); console.log(branch_id); @@ -1391,11 +1395,8 @@ $(document).ready(function(){ // myModal.show(); $(this).val('').select2(); - $('#client_type').removeClass('readonly-select ');; + $('#actcual_clients').hide(); appendVehicleForm(); - }else{ - $('#client_type').prop('disabled', true); - $('#client_type').addClass('readonly-select '); } }) @@ -1493,6 +1494,7 @@ $(document).ready(function(){ $('#client_branch_id').val('').select2(); $('#vehicle_row_div').empty(); $('#client_row_div').empty(); + $('#actcual_clients').show(); var client_type = $('#client_type').val(); var value = $(this).val(); @@ -5008,7 +5010,7 @@ function toggleClient(input) { function removeVehicleForm(){ $('#vehicle_row_div').empty(); - $('#client_type').addClass('readonly-select '); + $('#actcual_clients').show(); } function removeClientForm(){ @@ -5025,9 +5027,9 @@ function getVehicleFormData() { if (vhno === "" && rc === "") { toastr.warning("Please enter any one of these: Vehicle No or Chassis No", "WARNING"); + return; } - var isValid = $('#vehicle_form_row_div').parsley().validate(); if (!isValid) { @@ -5045,7 +5047,7 @@ function getVehicleFormData() { console.log("✅ Added field:", name, "=", value); } }); - data["client_type"] = client_type; + // data["client_type"] = client_type; console.log("📌 Final Data Object:", data); @@ -5057,14 +5059,26 @@ function getVehicleFormData() { if (response.status == true) { toastr.success(response.message, 'SUCCESS'); - getClientAndBranchAndPolicy(); + appendClients(response.clients, response.client_id); + appendVehicles(response.vehicles, response.vehicle_id); + appendBranch(response.branches, response.branch_id); + if(response.data.client_type == 1){ + $('.branchdiv').show(); + $('#table_tr_34').show(); + $('#table_tr_37').show(); + }else{ + $('.branchdiv').hide(); + $('#table_tr_34').hide(); + $('#table_tr_37').hide(); + } + $('#client_type').val(response.data?.client_type ?? "").trigger('change'); } else { toastr.warning(response.message, 'WARNING'); } $('#client_row_div').empty(); $('#vehicle_row_div').empty(); - $('#client_type').addClass('readonly-select '); + $('#actcual_clients').show(); }, function(xhr, status, error) { console.error('Error fetching data:', error); @@ -5107,7 +5121,8 @@ function getClientFormData() { if (response.status == true) { toastr.success(response.message, 'SUCCESS'); - getClientAndBranchAndPolicy() + appendClients(response.clients, response.client_id); + appendBranch(response.branches, response.branch_id); } else { toastr.warning(response.message, 'WARNING'); } @@ -5177,6 +5192,15 @@ function appendVehicleForm(){
+
+ + +
+
+ oninput="validateInputForClient(this, 'client_branch', 'gst')" required>
-
@@ -5420,67 +5503,4 @@ $('#client_type').on('change', function() { }); -$('#client_type').on('change', function() { - - let btn = $("#vehicle_client_btn"); - let client_type = $(this).val(); - - if(client_type == 1){ - - if(btn.is(':checked')){ - $('.v_group_client').show(); - $('.v_individual_client').hide(); - $(".v_group_client").find("select, input, textarea").val("").prop("required", true); - $(".v_individual_client").find("select, input, textarea").val("").prop("required", false); - }else{ - $('.v_group_client').hide(); - $('.v_individual_client').hide(); - $(".v_group_client").find("select, input, textarea").val("").prop("required", false); - $(".v_individual_client").find("select, input, textarea").val("").prop("required", false); - - $('.old_group_client').show(); - $(".old_group_client").find("select, input, textarea").val("").prop("required", true); - $(".v_common").find("select, input, textarea").val("").prop("required", false); - } - - }else{ - - if(btn.is(':checked')){ - $('.v_group_client').hide(); - $('.v_individual_client').show(); - $(".v_group_client").find("select, input, textarea").val("").prop("required", false); - $(".v_individual_client").find("select, input, textarea").val("").prop("required", true); - }else{ - $('.v_group_client').hide(); - $('.v_individual_client').hide(); - $(".v_group_client").find("select, input, textarea").val("").prop("required", false); - $(".v_individual_client").find("select, input, textarea").val("").prop("required", false); - - $('.old_group_client').hide(); - $(".old_group_client").find("select, input, textarea").val("").prop("required", false); - $(".v_common").find("select, input, textarea").val("").prop("required", false); - - } - } - - $.each(client_list, function(index, item) { - if (item.client_type == client_type) { - - let client_show_name = item.client_name; - if (item.client_type == 2) { - // client_show_name = item.client_name + ' - ' + (item.dob ?? '') + (item.pan ?? ''); - client_show_name = item.client_name + (item.dob ? ('- (' + item.dob + ' )' ) : '') + (item.pan ? ('- ' + item.pan ) : ''); - } - var option = $('