CHANGE_LEVEL_CONTECT : RV
This commit is contained in:
parent
5eeea0bbd6
commit
f2dc074edf
@ -867,21 +867,27 @@ class ClientController extends AdminController
|
||||
$insert = $this->clientBranchModel->insert($data);
|
||||
|
||||
if ($insert) {
|
||||
for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
||||
// Prepare data to insert
|
||||
$data = [
|
||||
'contact_type' => 'client',
|
||||
'ref_id' => $insert,
|
||||
'created_by' => get_session_userid(),
|
||||
'name' => $this->request->getPost('name')[$i],
|
||||
'email' => $this->request->getPost('email')[$i],
|
||||
'mobile' => $this->request->getPost('mobile')[$i],
|
||||
'designation' => $this->request->getPost('designation')[$i]
|
||||
];
|
||||
$contacts = $this->levelContactModel->insert($data);
|
||||
}
|
||||
$level_contact_data = $this->request->getPost('level_contect_data');
|
||||
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
||||
$this->saveLevelContacts($level_contact_data, $insert);
|
||||
}
|
||||
|
||||
// if ($insert) {
|
||||
// for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
||||
// // Prepare data to insert
|
||||
// $data = [
|
||||
// 'contact_type' => 'client',
|
||||
// 'ref_id' => $insert,
|
||||
// 'created_by' => get_session_userid(),
|
||||
// 'name' => $this->request->getPost('name')[$i],
|
||||
// 'email' => $this->request->getPost('email')[$i],
|
||||
// 'mobile' => $this->request->getPost('mobile')[$i],
|
||||
// 'designation' => $this->request->getPost('designation')[$i]
|
||||
// ];
|
||||
// $contacts = $this->levelContactModel->insert($data);
|
||||
// }
|
||||
// }
|
||||
|
||||
if ($insert) {
|
||||
$branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll();
|
||||
$branchData['role'] = get_role_id();
|
||||
@ -968,24 +974,29 @@ class ClientController extends AdminController
|
||||
$insert = $this->clientBranchModel->update($id, $data);
|
||||
$this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]);
|
||||
|
||||
|
||||
if ($insert) {
|
||||
|
||||
$this->levelContactModel->where('ref_id', $id)->where('contact_type', 'client')->delete();
|
||||
for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
||||
$data = [
|
||||
'contact_type' => 'client',
|
||||
'ref_id' => $id,
|
||||
'updated_by' => get_session_userid(),
|
||||
'name' => $this->request->getPost('name')[$i],
|
||||
'email' => $this->request->getPost('email')[$i],
|
||||
'mobile' => $this->request->getPost('mobile')[$i],
|
||||
'designation' => $this->request->getPost('designation')[$i]
|
||||
];
|
||||
$contacts = $this->levelContactModel->insert($data);
|
||||
}
|
||||
$level_contact_data = $this->request->getPost('level_contect_data');
|
||||
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
||||
$this->saveLevelContacts($level_contact_data, $insert);
|
||||
}
|
||||
|
||||
// if ($insert) {
|
||||
|
||||
// $this->levelContactModel->where('ref_id', $id)->where('contact_type', 'client')->delete();
|
||||
// for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
||||
// $data = [
|
||||
// 'contact_type' => 'client',
|
||||
// 'ref_id' => $id,
|
||||
// 'updated_by' => get_session_userid(),
|
||||
// 'name' => $this->request->getPost('name')[$i],
|
||||
// 'email' => $this->request->getPost('email')[$i],
|
||||
// 'mobile' => $this->request->getPost('mobile')[$i],
|
||||
// 'designation' => $this->request->getPost('designation')[$i]
|
||||
// ];
|
||||
// $contacts = $this->levelContactModel->insert($data);
|
||||
// }
|
||||
// }
|
||||
|
||||
if ($insert) {
|
||||
$branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
|
||||
return $this->respond([
|
||||
@ -1005,6 +1016,24 @@ class ClientController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function saveLevelContacts($level_contact_data, $branch_id)
|
||||
{
|
||||
if (!empty($level_contact_data) && is_array($level_contact_data)) {
|
||||
foreach ($level_contact_data as $value) {
|
||||
if (!empty($value['id'])) {
|
||||
$id = $value['id'];
|
||||
unset($value['id']);
|
||||
$this->levelContactModel->update($id, $value);
|
||||
} else {
|
||||
unset($value['id']);
|
||||
$value['contact_type'] = "client";
|
||||
$value['ref_id'] = $branch_id ?? null;
|
||||
$this->levelContactModel->insert($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function createClientPolicy()
|
||||
|
||||
@ -480,7 +480,7 @@ class RestAuthenticationController extends AdminController
|
||||
try {
|
||||
// mobile number
|
||||
$otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null;
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null;
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_no) ? $this->request->getJSON()->mobile_no : null;
|
||||
// email id
|
||||
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
|
||||
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : null;
|
||||
@ -510,7 +510,7 @@ class RestAuthenticationController extends AdminController
|
||||
}
|
||||
|
||||
|
||||
if(isset($this->request->getJSON()->mobile_number)){
|
||||
if(isset($this->request->getJSON()->mobile_no)){
|
||||
|
||||
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id')
|
||||
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
|
||||
|
||||
@ -98,7 +98,7 @@ input:checked + .slider:before {
|
||||
<label for="short_name">Client Short Name<span
|
||||
class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="short_name"
|
||||
placeholder="Enter Short Name" value="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>" name="short_name" required>
|
||||
placeholder="Enter Short Name" value="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>" name="short_name" onkeyup="validateInput(this, 'clients', 'short_name', 'clientBtnSubmit')" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -137,7 +137,7 @@ input:checked + .slider:before {
|
||||
|
||||
<div class="form-group text-right m-b-0">
|
||||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||||
id="btnSubmit">Submit</button>
|
||||
id="clientBtnSubmit">Submit</button>
|
||||
<button type="button" class="btn btn-secondary waves-effect btnBack"
|
||||
id="btnBack">Cancel</button>
|
||||
</div>
|
||||
|
||||
@ -168,6 +168,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<input type="hidden" name="branch_table_pk[]" id="branch_table_pk" >
|
||||
<div class="form-group col-md-6">
|
||||
<label for="first_name">Name<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Name"
|
||||
@ -184,12 +185,12 @@
|
||||
<div class="form-group col-md-6">
|
||||
<label for="last_name">Email<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Email"
|
||||
name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateInput(this, 'level_contacts', 'email')" required>
|
||||
name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onkeyup="validateInput(this, 'level_contacts', 'email', 'branchBtnSubmit')" required>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="mobile">Mobile<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Mobile"
|
||||
name="mobile[]" id="mobile" onchange="checkMobileNumber(this)"
|
||||
name="mobile[]" id="mobile" onkeyup="validateInput(this, 'level_contacts', 'mobile', 'branchBtnSubmit')"
|
||||
onkeypress="return onlyNumbers(event)" maxlength="10" minlength="10"
|
||||
data-parsley-type-message="Please enter a valid 10-digit mobile number."
|
||||
data-parsley-required-message="Please enter a valid 10-digit mobile number."
|
||||
@ -209,7 +210,7 @@
|
||||
</div>
|
||||
<div class="form-group text-right m-b-0">
|
||||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||||
id="btnSubmit">Submit</button>
|
||||
id="branchBtnSubmit">Submit</button>
|
||||
<button type="button" class="btn btn-secondary waves-effect btnBack"
|
||||
id="btnBack">Cancel</button>
|
||||
</div>
|
||||
@ -354,6 +355,9 @@ $("#branch_form").submit(function(event) {
|
||||
var selectedValues = $("#selected").val();
|
||||
console.log(selectedValues, selectedValues);
|
||||
|
||||
let level_contect_data = getContactsData();
|
||||
console.log('level_contect_data', level_contect_data);
|
||||
|
||||
event.preventDefault();
|
||||
branch_PrimaryKey = $('#client_id_branch').val();
|
||||
|
||||
@ -377,11 +381,14 @@ $("#branch_form").submit(function(event) {
|
||||
var formData = new FormData($('#branch_form')[0]);
|
||||
|
||||
const jsonString = JSON.stringify(selectedValues);
|
||||
const level_contect_data_json_string = JSON.stringify(level_contect_data);
|
||||
console.log('jsonString', jsonString);
|
||||
console.log('level_contect_data_json_string', level_contect_data_json_string);
|
||||
|
||||
|
||||
// Append the JSON string to the FormData object
|
||||
formData.append('units', jsonString);
|
||||
formData.append('level_contect_data', level_contect_data_json_string);
|
||||
|
||||
$.ajax({
|
||||
data: formData,
|
||||
@ -532,10 +539,24 @@ $('body').on('click', '.btnBranchEdit', function() {
|
||||
|
||||
appendOption(res.data.units)
|
||||
|
||||
$('#name').val(res.contact[0].name);
|
||||
$('#email').val(res.contact[0].email);
|
||||
$('#mobile').val(res.contact[0].mobile);
|
||||
$('#designation').val(res.contact[0].designation);
|
||||
// $('#name').val(res.contact[0].name);
|
||||
// $('#email').val(res.contact[0].email);
|
||||
// $('#mobile').val(res.contact[0].mobile);
|
||||
// $('#designation').val(res.contact[0].designation);
|
||||
|
||||
if (res.contact && res.contact.length > 0 && res.contact[0]) {
|
||||
$('#branch_table_pk').val(res.contact[0].id || '');
|
||||
$('#name').val(res.contact[0].name || '');
|
||||
$('#email').val(res.contact[0].email || '');
|
||||
$('#mobile').val(res.contact[0].mobile || '');
|
||||
$('#designation').val(res.contact[0].designation || '');
|
||||
} else {
|
||||
$('#branch_table_pk').val('');
|
||||
$('#name').val('');
|
||||
$('#email').val('');
|
||||
$('#mobile').val('');
|
||||
$('#designation').val('');
|
||||
}
|
||||
|
||||
res.contact.shift();
|
||||
// console.log(res.contact.length)
|
||||
@ -586,6 +607,7 @@ function appendContactHtml(contact = false, reset = false) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="hidden" name="branch_table_pk[]" id="${uniqueId}_branch_table_pk" value="${contact !== undefined && contact !== false ? contact.id : ''}">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_first_name">Name<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.name : ''}" type="text" class="form-control" placeholder="Enter Contact Name" name="name[]" id="${uniqueId}_name" required>
|
||||
@ -598,11 +620,11 @@ function appendContactHtml(contact = false, reset = false) {
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_last_name">Email<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.email : ''}" type="text" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateInput(this, 'level_contacts', 'email')" required>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.email : ''}" type="text" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateInput(this, 'level_contacts', 'email', 'branchBtnSubmit')" required>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_mobile">Mobile<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="text" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" onchange="checkMobileNumber(this)" onkeypress = "return onlyNumbers(event)" maxlength="10" min="10" data-parsley-type-message="Please enter a valid 10-digit mobile number." data-parsley-required-message="Please enter a valid 10-digit mobile number." required>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="text" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" onkeyup="validateInput(this, 'level_contacts', 'mobile', 'branchBtnSubmit')" onkeypress = "return onlyNumbers(event)" maxlength="10" min="10" data-parsley-type-message="Please enter a valid 10-digit mobile number." data-parsley-required-message="Please enter a valid 10-digit mobile number." required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="display: flex;">
|
||||
@ -775,7 +797,7 @@ function checkMobileNumber(input) {
|
||||
|
||||
}
|
||||
|
||||
function validateInput(input, table, field){
|
||||
function validateInput(input, table, field, submitBtnId){
|
||||
|
||||
let value = $(input).val();
|
||||
let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim();
|
||||
@ -788,11 +810,37 @@ function validateInput(input, table, field){
|
||||
checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) {
|
||||
if (isDuplicate) {
|
||||
toastr.warning(message, 'WARNING');
|
||||
$(input).val('')
|
||||
}
|
||||
// $(input).val('')
|
||||
$('#'+submitBtnId).prop('disabled', true);
|
||||
} else{
|
||||
$('#'+submitBtnId).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function getContactsData() {
|
||||
const contacts = [];
|
||||
|
||||
const ids = $('input[name="branch_table_pk[]"]');
|
||||
const names = $('input[name="name[]"]');
|
||||
const mobiles = $('input[name="mobile[]"]');
|
||||
const emails = $('input[name="email[]"]');
|
||||
const designations = $('input[name="designation[]"]');
|
||||
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
contacts.push({
|
||||
id: $(ids[i]).val() || null,
|
||||
name: $(names[i]).val(),
|
||||
mobile: $(mobiles[i]).val(),
|
||||
email: $(emails[i]).val(),
|
||||
designation: $(designations[i]).val()
|
||||
});
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user