diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 3cb43b5..249120d 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -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() diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index aaa25ff..b711005 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -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') diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php index 08c991a..ab3233a 100755 --- a/app/Views/client_basic_info.php +++ b/app/Views/client_basic_info.php @@ -98,7 +98,7 @@ input:checked + .slider:before { + placeholder="Enter Short Name" value="" name="short_name" onkeyup="validateInput(this, 'clients', 'short_name', 'clientBtnSubmit')" required> @@ -137,7 +137,7 @@ input:checked + .slider:before {
+ id="clientBtnSubmit">Submit
diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index fe75c7b..875de04 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -168,6 +168,7 @@
+
+ name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onkeyup="validateInput(this, 'level_contacts', 'email', 'branchBtnSubmit')" required>
+ id="branchBtnSubmit">Submit
@@ -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) {
+
@@ -598,11 +620,11 @@ function appendContactHtml(contact = false, reset = false) {
- +
- +
@@ -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; +} +