CHANGE_BDS : RV

This commit is contained in:
VENKATESHWARAN 2025-09-19 14:35:30 +05:30
parent 82286bb9c2
commit c05735a552
4 changed files with 208 additions and 107 deletions

View File

@ -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

View File

@ -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;

View File

@ -226,7 +226,7 @@
</select>
</div>
</div>
<div class="row">
<div class="row" id="actcual_clients">
<div class="form-group col-md-3 client_type_div">
<label for="client_type">Client Type<span class="text-danger">*</span></label>
@ -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(){
</select>
</div>
<div class="form-group col-md-3">
<label for="client_type">Client Type<span class="text-danger">*</span></label>
<select class="form-control" id="owner_client_type" name="client_type" required>
<option value="">Select Client type</option>
<option value="1">Group</option>
<option value="2">Individual</option>
</select>
</div>
<div class="form-group col-md-3 old_client">
<label for="owner">Owner Name <span class="text-danger">*</span></label>
<select class="form-control" id="owner" name="owner" required>
@ -5248,19 +5272,19 @@ function appendVehicleForm(){
$('#owner').select2();
$('#owner_branch').select2();
$("#vehicle_form_row_div").on("input change", "input, select, textarea", function () {
if ($("#client_type").val() === "") {
alert("Please select the client type first");
if ($(this).is(":checkbox")) {
// uncheck checkbox
$(this).prop("checked", false);
} else {
// clear text/select/textarea
$(this).val("");
}
$("#client_type").focus(); // focus back to client_type
}
});
// $("#vehicle_form_row_div").on("input change", "input, select, textarea", function () {
// if ($("#client_type").val() === "") {
// alert("Please select the client type first");
// if ($(this).is(":checkbox")) {
// // uncheck checkbox
// $(this).prop("checked", false);
// } else {
// // clear text/select/textarea
// $(this).val("");
// }
// $("#client_type").focus(); // focus back to client_type
// }
// });
$('#owner').change(function(){
@ -5274,6 +5298,69 @@ function appendVehicleForm(){
})
$('#owner_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 = $('<option>', {
value: item.id,
text: client_show_name,
'data-cn': item.client_name,
'data-ct': item.client_type
});
$('#owner').append(option);
}
});
});
}
function appendClientForm(){
@ -5329,13 +5416,9 @@ function appendClientForm(){
<label for="gst">GST <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="gst" name="gst"
placeholder="Enter GST Number"
oninput="validateInputForClient(this, 'client_branch', 'gst')"
data-parsley-error-message="Invalid GST Number. Example: 12ABCDE1234F5Z6"
data-parsley-trigger="change"
data-parsley-pattern="^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}Z{1}[A-Z\d]{1}$" required>
oninput="validateInputForClient(this, 'client_branch', 'gst')" required>
</div>
</div>
<div class="row">
<div class="col-md-12 text-right m-b-0">
@ -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 = $('<option>', {
value: item.id,
text: client_show_name,
'data-cn': item.client_name,
'data-ct': item.client_type
});
$('#owner').append(option);
}
});
});
</script>

View File

@ -731,7 +731,7 @@ function getClientAndBranchAndPolicy()
});
}
function appendClients(data)
function appendClients(data, client_id = null)
{
$('#client_id').empty();
@ -761,11 +761,15 @@ function appendClients(data)
class: item.client_type == 1 ? 'group' : item.client_type == 2 ? 'individual' : ''
});
if (client_id == item.id) {
option.attr('selected', true);
}
$('#client_id').append(option);
});
}
function appendVehicles(data, vehicle_id)
function appendVehicles(data, vehicle_id = null)
{
$('#vehicle_no').empty();
@ -794,7 +798,7 @@ function appendVehicles(data, vehicle_id)
});
}
function appendBranch(data)
function appendBranch(data, branch_id = null)
{
$('#client_branch_id').empty();
@ -810,6 +814,11 @@ function appendBranch(data)
value: item.id,
text: item.branch_name
});
if (branch_id == item.id) {
option.attr('selected', true);
}
$('#client_branch_id').append(option);
});
}