539 lines
23 KiB
PHP
Executable File
539 lines
23 KiB
PHP
Executable File
<div class="tab-pane fade" id="branch-tab">
|
|
|
|
<div class="row float-right" style="padding-bottom: 10px;position: relative;right: 13px;">
|
|
<button type="button" id="btnBranchAdd" class="btn btn-primary waves-effect waves-light btn-sm"><span class="fa fa-plus-square" aria-hidden="true" style="padding: 5px 10px;"></span>Add Branch</button>
|
|
</div>
|
|
|
|
<div class="table-responsive" id="branch_table" >
|
|
|
|
<table class="table table-borderless table-nowrap mb-0">
|
|
<thead class="thead-light">
|
|
<tr>
|
|
<th>Branch Name</th>
|
|
<th>Branch Code</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="insurer_branch_list">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="row" id="add_branch">
|
|
<div class="col-12">
|
|
<div class="card-body">
|
|
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
|
|
<button type="button" id="btnBranchBack" class="btn btn-primary waves-effect waves-light btn-sm btnBack"><span class="fa fa-list" aria-hidden="true" style="padding: 5px 10px;"></span>Back To List</button>
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<form role="form" class="parsley-examples" method="post" id="insurer_branch_form"
|
|
enctype="multipart/form-data">
|
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
|
<input type="hidden" name="PrimaryKey" id="insurer_Branch_PrimaryKey" />
|
|
<input type="hidden" name="insurer_id" id="insurer_id_branch" value="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>"/>
|
|
<div class="form-group">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<label for="branch_name">Branch Name<span
|
|
class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="branch_name"
|
|
placeholder="Enter Branch Name" name="branch_name" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="branch_code">Branch Code<span
|
|
class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="branch_code"
|
|
placeholder="Enter Branch Code" name="branch_code" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<label for="address1">Address Line 1<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="address1" name="address1" placeholder="Enter Address 1" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="address2">Address Line 2<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" id="address2" placeholder="Enter Address 2" name="address2">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-3">
|
|
<label for="state">State<span
|
|
class="text-danger">*</span></label>
|
|
<select class="form-control" id="state" name="state" required>
|
|
<option value="">Select State</option>
|
|
<?php foreach($state as $value) { ?>
|
|
<option value="<?= $value['id'] ?>"><?= $value['state'] ?></option>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="district">District<span
|
|
class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="district"
|
|
placeholder="Enter District" name="district" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="city">City<span
|
|
class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="branch_city"
|
|
placeholder="Enter City" name="city" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="gst">Pincode<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="pincode" placeholder="Enter Pincode" name="pincode" required>
|
|
</div>
|
|
</div>
|
|
|
|
<hr>
|
|
<h6 class="header-title">Contact 1</h6>
|
|
<br>
|
|
|
|
<div class="form-row">
|
|
<input type="hidden" name="primarykey[]" id="contact_id_1" value=""/>
|
|
<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" name="name[]" id="name" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="designation">Designation<span class="text-danger">*</span></label>
|
|
<input value="" type="text" class="form-control" placeholder="Enter Designation Name" name="designation[]" id="designation" required>
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<label for="last_name">Email<span class="text-danger">*</span></label>
|
|
<input value="" type="email" data-parsley-type="email" class="form-control" placeholder="Enter Contact Email" name="email[]" id="email" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="mobile">Mobile<span class="text-danger">*</span></label>
|
|
<input name="mobile[]" pattern="[0-9]{10}" value="" type="tel" data-parsley-type="number" data-parsley-length="[10,10]" class="form-control" placeholder="Enter Contact Mobile" id="mobile" required>
|
|
</div>
|
|
</div>
|
|
<div class="form-group" style="display: flex;">
|
|
<button style="margin-right: 10px;" type="button" class="btn btn-primary btn-sm ac" onclick="appendContactHtml()" id="add">Add Contact</button>
|
|
<button type="button" class="btn btn-danger btn-sm" onclick="removeContact(this)" id="${uniqueId}_remove">Remove</button>
|
|
</div>
|
|
|
|
<div id="container"></div>
|
|
|
|
</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>
|
|
<button type="button" class="btn btn-secondary waves-effect btnBack"
|
|
id="btnBack">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div> <!-- end col-->
|
|
</div>
|
|
<!-- end -->
|
|
|
|
|
|
<script>
|
|
|
|
var contactCount = 1;
|
|
var insurer_branch_form_action = '';
|
|
var insurer_Branch_PrimaryKey = $('#insurer_id_branch').val();
|
|
|
|
$(document).ready(function () {
|
|
|
|
insurer_Branch_PrimaryKey = $('#insurer_id_branch').val();
|
|
|
|
$('#add_branch').hide();
|
|
$('.btnBack').hide();
|
|
|
|
if(insurer_Branch_PrimaryKey !== ''){
|
|
|
|
var branchTable = '';
|
|
var data = <?= isset($insuer_branch) ? json_encode($insuer_branch) : '[]' ?>;
|
|
$.each(data, function(index, item) {
|
|
branchTable += `
|
|
<tr>
|
|
<td>${item.branch_name}</td>
|
|
<td>${item.branch_code}</td>
|
|
<td>
|
|
<a class="mdi mdi-lead-pencil btnBranchEdit" href="#" data-id="${item.id}" style="font-size:18px;"></a>
|
|
<a style="color:#02a8b5" data-id="${item.id}" onclick="removeInsurerBranch(this)"><i data-id="${item.id}" class="mdi mdi-delete" style="font-size:18px;"></i></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
$('#insurer_branch_list').append(branchTable);
|
|
}
|
|
|
|
});
|
|
|
|
|
|
$('#btnBranchAdd').click(function(){
|
|
|
|
$("#insurer_branch_form")[0].reset();
|
|
contactCount = 1
|
|
insurer_branch_form_action = '<?= base_url("master/insurer/branch/create"); ?>';
|
|
$('#add_branch').show();
|
|
$('#branch_table').hide();
|
|
$('.btnBack').show();
|
|
$('#btnBranchAdd').hide();
|
|
|
|
$('#branch_name').val('');
|
|
$('#branch_code').val('');
|
|
$('#state').val('');
|
|
$('#district').val('');
|
|
$('#branch_city').val('');
|
|
|
|
$('#name').val('');
|
|
$('#email').val('');
|
|
$('#mobile').val('');
|
|
$('#designation').val('');
|
|
contactCount = 1
|
|
|
|
var addButton = document.getElementById('add');
|
|
if (addButton.style.display === 'none') {
|
|
addButton.style.display = 'block';
|
|
}
|
|
|
|
var buttonIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
|
|
for (var i = 0; i < buttonIds.length; i++) {
|
|
var firstElement = buttonIds[i].split('_')[0];
|
|
console.log(firstElement);
|
|
|
|
// Find the element by its ID
|
|
var elementToRemove = document.getElementById(firstElement);
|
|
console.log(elementToRemove);
|
|
|
|
if (elementToRemove) {
|
|
console.log(elementToRemove);
|
|
elementToRemove.parentNode.removeChild(elementToRemove);
|
|
}
|
|
localStorage.removeItem('buttonIds')
|
|
}
|
|
})
|
|
|
|
$('.btnBack').click(function(){
|
|
|
|
$("#insurer_branch_form")[0].reset();
|
|
contactCount = 1
|
|
$('#add_branch').hide();
|
|
$('#branch_table').show();
|
|
$('.btnBack').hide();
|
|
$('#btnBranchAdd').show();
|
|
|
|
$('#branch_name').val('');
|
|
$('#branch_code').val('');
|
|
$('#state').val('');
|
|
$('#district').val('');
|
|
$('#branch_city').val('');
|
|
|
|
$('#name').val('');
|
|
$('#email').val('');
|
|
$('#mobile').val('');
|
|
$('#designation').val('');
|
|
|
|
})
|
|
|
|
|
|
$("#insurer_branch_form").submit(function(events) {
|
|
console.log(1, insurer_branch_form_action);
|
|
events.preventDefault();
|
|
var isValid = $('#insurer_branch_form').parsley().validate();
|
|
if (isValid) {
|
|
|
|
var formData = new FormData($('#insurer_branch_form')[0]);
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
$.ajax({
|
|
data: formData,
|
|
url: insurer_branch_form_action,
|
|
type: "POST",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
$("#insurer_branch_form")[0].reset();
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
console.log(res);
|
|
$('#insurer_branch_list tr').remove();
|
|
var insurerBranchTableInsert = ''
|
|
$.each(res.data, function(index, item) {
|
|
insurerBranchTableInsert += `
|
|
<tr>
|
|
<td>${item.branch_name}</td>
|
|
<td>${item.branch_code}</td>
|
|
<td>
|
|
<a class="mdi mdi-lead-pencil btnBranchEdit" href="#" data-id="${item.id}" style="font-size:18px;"></a>
|
|
<a style="color:#02a8b5" data-id="${item.id}" onclick="removeInsurerBranch(this)"><i data-id="${item.id}" class="mdi mdi-delete" style="font-size:18px;"></i></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
$('#insurer_branch_list').append(insurerBranchTableInsert);
|
|
$('#add_branch').hide();
|
|
$('#branch_table').show();
|
|
$('.btnBack').hide();
|
|
$('#btnBranchAdd').show();
|
|
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
toastr.warning('Something Wrong!', 'Warning');
|
|
}, 1000);
|
|
}
|
|
});
|
|
|
|
}
|
|
});
|
|
|
|
|
|
$('body').on('click', '.btnBranchEdit', function () {
|
|
$('#container').html("");
|
|
contactCount = 1;
|
|
var branch_id = $(this).attr('data-id');
|
|
$('#insurer_Branch_PrimaryKey').val(branch_id);
|
|
|
|
insurer_branch_form_action = '<?= base_url("master/insurer/branch/edit"); ?>';
|
|
|
|
console.log(insurer_branch_form_action)
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url('master/insurer/branch/editget/');?>'+branch_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function (res) {
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
$('#add_branch').show();
|
|
$('#branch_table').hide();
|
|
$('.btnBack').show();
|
|
$('#btnBranchAdd').hide();
|
|
$('#branch_name').val(res.insurerbranch.branch_name);
|
|
$('#branch_code').val(res.insurerbranch.branch_code);
|
|
$('#state option[value="' + res.insurerbranch.state + '"]').prop('selected', true);
|
|
$('#district').val(res.insurerbranch.district);
|
|
$('#branch_city').val(res.insurerbranch.city);
|
|
$('#pincode').val(res.insurerbranch.pincode);
|
|
$('#address1').val(res.insurerbranch.address1);
|
|
$('#address2').val(res.insurerbranch.address2);
|
|
|
|
$('#contact_id_1').val(res.levelcontact[0].id);
|
|
$('.form-row').find('#name').val(res.levelcontact[0].name);
|
|
$('#email').val(res.levelcontact[0].email);
|
|
$('#mobile').val(res.levelcontact[0].mobile);
|
|
$('#designation').val(res.levelcontact[0].designation);
|
|
|
|
res.levelcontact.shift();
|
|
$.each(res.levelcontact, function(index, contact) {
|
|
if (contact !== undefined) {
|
|
appendContactHtml(contact);
|
|
}
|
|
});
|
|
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
toastr.warning('Something Wrong!', 'Warning');
|
|
}, 1000);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function appendContactHtml(contact = false, reset = false) {
|
|
|
|
console.log('appendContactHtml function called ')
|
|
contactCount++;
|
|
|
|
var container = document.getElementById('container');
|
|
var uniqueId = Date.now().toString();
|
|
|
|
var html = `
|
|
<div id="${uniqueId}">
|
|
<hr>
|
|
<h6 class="header-title">Contact ${contactCount}</h6>
|
|
<br>
|
|
<div class="form-row">
|
|
<input type="hidden" name="primarykey[]" id="contact_id_1" 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>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="${uniqueId}_last_name">Email<span class="text-danger">*</span></label>
|
|
<input data-parsley-type="email" value="${contact !== undefined && contact !== false ? contact.email : ''}" type="email" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" required>
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<label for="${uniqueId}_mobile">Mobile<span class="text-danger">*</span></label>
|
|
<input data-parsley-type="number" data-parsley-length="[10,10]" pattern="[0-9]{10}" value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="tel" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="${uniqueId}_designation">Designation<span class="text-danger">*</span></label>
|
|
<input value="${contact !== undefined && contact !== false ? contact.designation : ''}" type="text" class="form-control" placeholder="Enter Designation Name" name="designation[]" id="${uniqueId}_designation" required>
|
|
</div>
|
|
</div>
|
|
<div class="form-group" style="display: flex;">
|
|
<button style="margin-right: 10px;" type="button" class="btn btn-primary btn-sm ac" onclick="appendContactHtml()" id="${uniqueId}_add">Add Contact</button>
|
|
<button type="button" class="btn btn-danger btn-sm" onclick="removeContact(this)" id="${uniqueId}_remove">Remove</button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
if(reset == false){
|
|
container.insertAdjacentHTML('beforeend', html);
|
|
storeButtonId(uniqueId + '_add');
|
|
|
|
if (contactCount >= 3) {
|
|
hideStoredAddButtons();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function removeContact(button) {
|
|
var uniqueId = button.id.split("_")[0];
|
|
var contactSection = document.getElementById(uniqueId);
|
|
|
|
if (contactSection) {
|
|
contactSection.parentNode.removeChild(contactSection);
|
|
contactCount --;
|
|
|
|
if (contactCount < 3) {
|
|
var addButton = document.querySelector('.ac');
|
|
if (addButton) {
|
|
addButton.style.display = 'block';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function storeButtonId(id) {
|
|
|
|
var buttonIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
|
|
buttonIds.push(id);
|
|
localStorage.setItem('buttonIds', JSON.stringify(buttonIds));
|
|
}
|
|
|
|
|
|
function hideStoredAddButtons() {
|
|
var storedIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
|
|
storedIds.forEach(function(id) {
|
|
var addButton = document.getElementById(id);
|
|
var first_addButton = document.querySelector('.ac')
|
|
if (addButton) {
|
|
addButton.style.display = 'none';
|
|
first_addButton.style.display = 'none';
|
|
}
|
|
});
|
|
}
|
|
|
|
function showNextAddButton() {
|
|
var storedIds = JSON.parse(localStorage.getItem('buttonIds')) || [];
|
|
var addButtonShown = false;
|
|
|
|
// Iterate through the stored IDs to find the next "Add" button to show
|
|
storedIds.forEach(function(id) {
|
|
if (!addButtonShown) {
|
|
var addButton = document.getElementById(id);
|
|
if (addButton && addButton.style.display === 'none') {
|
|
addButton.style.display = 'block';
|
|
addButtonShown = true; // Set to true once an "Add" button is shown
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function validateForm() {
|
|
var isValid = true;
|
|
|
|
$('#insurer_branch_form input, #insurer_branch_form select').each(function() {
|
|
|
|
if ($(this).is('input[name="emial[]"]') || $(this).is('input[type="text"]') || $(this).is('select') ) {
|
|
if ($.trim($(this).val()) == '') {
|
|
isValid = false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
return isValid;
|
|
}
|
|
|
|
|
|
function removeInsurerBranch(element) {
|
|
|
|
Swal.fire({
|
|
title: "Are you sure?",
|
|
text: "You need to remove this insurer branch.",
|
|
icon: "info",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Yes",
|
|
}).then((result) => {
|
|
|
|
if (result.isConfirmed) {
|
|
var id = element.getAttribute('data-id');
|
|
var form_action = '<?= base_url("master/insurer/branch/remove/") ?>' + id;
|
|
$.ajax({
|
|
url: form_action,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
// console.log(res.status == true);
|
|
if(res){
|
|
if (res.status == true) {
|
|
toastr.success('Insurer branch removed successfully', 'Success');
|
|
location.reload();
|
|
} else {
|
|
toastr.warning('Failed to remove insurer branch', 'Warning');
|
|
}
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
toastr.warning('Failed to remove insurer branch', 'Warning');
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
</script>
|