447 lines
17 KiB
PHP
Executable File
447 lines
17 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 Policies</button>
|
|
</div>
|
|
|
|
<div class="table-responsive" id="branch_table" >
|
|
|
|
<table class="table table-borderless table-nowrap mb-0" id="table-policies">
|
|
<thead class="thead-light">
|
|
<tr>
|
|
<th>Insurer</th>
|
|
<th>Name</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="policies_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="tpa_branch_form" enctype="multipart/form-data">
|
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
|
<input type="hidden" name="PrimaryKey" id="policy_type_PrimaryKey" />
|
|
<input type="hidden" name="policy_type_id" id="policy_type_id" value="<?= isset($policytype['id']) ? $policytype['id'] : '' ?>"/>
|
|
<div class="form-group">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<label for="insurer_id">Insurer<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="insurer_id" name="insurer_id" required>
|
|
<option value="">Select Insurer</option>
|
|
<?php if (!empty($insurer)) { foreach ($insurer as $insurer) : ?>
|
|
<option value="<?= $insurer['id'] ?>"><?= $insurer['name'] ?></option>
|
|
<?php endforeach; } ?>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
<div class="form-group col-md-6">
|
|
<label for="name">Polices Name<span
|
|
class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="name"
|
|
placeholder="Enter Name" name="name" required>
|
|
</div>
|
|
</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>
|
|
|
|
$(document).ready(function() {
|
|
$("#insurer_id").select2();
|
|
});
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
var policy_type_PrimaryKey = $('#policy_type_id').val();
|
|
var tpa_branch_form_action = '';
|
|
|
|
$('#add_branch').hide();
|
|
$('.btnBack').hide();
|
|
|
|
|
|
loadPoliciesList();
|
|
|
|
|
|
setTimeout(() => {
|
|
$('#table-policies').DataTable({
|
|
paging: true ,
|
|
searching: false
|
|
});
|
|
}, 2000);
|
|
|
|
// var insurer_branch_action = '<?= base_url("master/insurer/list/"); ?>';
|
|
// if ($('#policy_type_id').val() != '') {
|
|
|
|
// $.ajax({
|
|
// url: insurer_branch_action,
|
|
// type: 'GET',
|
|
// success: function(response) {
|
|
// console.log(response);
|
|
// var branchTable = '';
|
|
// $.each(response.policies, function(index, item) {
|
|
// console.log(item);
|
|
// branchTable += `
|
|
// <tr>
|
|
// <td>${item.insurer_id}</td>
|
|
// <td>${item.name}</td>
|
|
// <td><a class="btnBranchEdit" data-id="${item.id}"><i data-id="${item.id}" class="mdi mdi-lead-pencil btnBranchEdit" style="font-size:18px;"></i></a></td>
|
|
// </tr>
|
|
// `;
|
|
// });
|
|
// $('#policies_list').append(branchTable);
|
|
// },
|
|
// error: function(xhr, status, error) {
|
|
// console.error(xhr.responseText);
|
|
// console.error(status, error);
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#btnBranchAdd').click(function(){
|
|
|
|
tpa_branch_form_action = '<?= base_url("master/policy/policies/createpost"); ?>';
|
|
|
|
$('#add_branch').show();
|
|
$('#branch_table').hide();
|
|
$('.btnBack').show();
|
|
$('#btnBranchAdd').hide();
|
|
|
|
$('#insurer_id').val('');
|
|
$('#name').val('');
|
|
$('#state').val('');
|
|
$('#district').val('');
|
|
$('#branch_city').val('');
|
|
|
|
$('#name0').val('');
|
|
$('#email0').val('');
|
|
$('#mobile0').val('');
|
|
$('#designation0').val('');
|
|
|
|
$('#name1').val('');
|
|
$('#email1').val('');
|
|
$('#mobile1').val('');
|
|
$('#designation1').val('');
|
|
|
|
$('#name2').val('');
|
|
$('#email2').val('');
|
|
$('#mobile2').val('');
|
|
$('#designation2').val('');
|
|
})
|
|
|
|
$('.btnBack').click(function(){
|
|
|
|
$('#add_branch').hide();
|
|
$('#branch_table').show();
|
|
$('.btnBack').hide();
|
|
$('#btnBranchAdd').show();
|
|
|
|
$('#insurer_id').val('');
|
|
$('#name').val('');
|
|
$('#state').val('');
|
|
$('#district').val('');
|
|
$('#branch_city').val('');
|
|
|
|
$('#name0').val('');
|
|
$('#email0').val('');
|
|
$('#mobile0').val('');
|
|
$('#designation0').val('');
|
|
|
|
$('#name1').val('');
|
|
$('#email1').val('');
|
|
$('#mobile1').val('');
|
|
$('#designation1').val('');
|
|
|
|
$('#name2').val('');
|
|
$('#email2').val('');
|
|
$('#mobile2').val('');
|
|
$('#designation2').val('');
|
|
|
|
})
|
|
|
|
|
|
if(policy_type_PrimaryKey !== ''){
|
|
|
|
var branchTable = '';
|
|
var data = <?= isset($policies) ? json_encode($policies) : '[]' ?>;
|
|
$.each(data, function(index, item) {
|
|
|
|
branchTable += `
|
|
<tr>
|
|
<td>${item.insurer_name}</td>
|
|
<td>${item.name}</td>
|
|
<td>
|
|
<a class="btnBranchEdit" data-id="${item.id}" href="#"><i data-id="${item.id}" class="mdi mdi-lead-pencil btnBranchEdit" style="font-size:18px;"></i></a>
|
|
<a style="color:#02a8b5" data-id="${item.id}" onclick="removePolicies(this)"><i data-id="${item.id}" class="mdi mdi-delete" style="font-size:18px;"></i></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
$('#policies_list').append(branchTable);
|
|
}
|
|
|
|
|
|
$("#tpa_branch_form").submit(function(events) {
|
|
events.preventDefault();
|
|
|
|
var isValid = $('#tpa_branch_form').parsley().validate();
|
|
|
|
if (isValid) {
|
|
|
|
var formData = new FormData($('#tpa_branch_form')[0]);
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
$('#policies_list').html("");
|
|
$.ajax({
|
|
data: formData,
|
|
url: tpa_branch_form_action,
|
|
type: "POST",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
|
|
console.log(res);
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
// console.log(res);
|
|
// $('#policies_list tr').remove();
|
|
var tpaBranchTableInsert = ''
|
|
$.each(res.data, function(index, item) {
|
|
tpaBranchTableInsert += `
|
|
<tr>
|
|
<td>${item.insurer_name}</td>
|
|
<td>${item.name}</td>
|
|
<td>
|
|
<a class="btnBranchEdit" data-id="${item.id}" href="#"><i data-id="${item.id}" class="mdi mdi-lead-pencil btnBranchEdit" style="font-size:18px;"></i></a>
|
|
<a style="color:#02a8b5" data-id="${item.id}" onclick="removePolicies(this)"><i data-id="${item.id}" class="mdi mdi-delete" style="font-size:18px;"></i></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
$('#policies_list').append(tpaBranchTableInsert);
|
|
// $('#policies_list').html("");
|
|
// loadPoliciesList();
|
|
|
|
|
|
$('#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 () {
|
|
var branch_id = $(this).attr('data-id');
|
|
tpa_branch_form_action = '<?= base_url("master/policy/policies/edit"); ?>';
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
$.ajax({
|
|
url: '<?php echo base_url('master/policy/policies/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();
|
|
$('#insurer_id').val(res.policies.insurer_id).change();
|
|
$('#name').val(res.policies.name);
|
|
$('#policy_type_PrimaryKey').val(res.policies.id);
|
|
|
|
// $('#policies_list').html(" ");
|
|
|
|
$.each(res.contact, function(index, contact) {
|
|
if (contact !== undefined) {
|
|
$('#name' + index).val(contact.name !== undefined ? contact.name : '');
|
|
$('#email' + index).val(contact.email !== undefined ? contact.email : '');
|
|
$('#mobile' + index).val(contact.mobile !== undefined ? contact.mobile : '');
|
|
$('#designation' + index).val(contact.designation !== undefined ? contact.designation : '');
|
|
}
|
|
});
|
|
|
|
},
|
|
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);
|
|
}
|
|
});
|
|
});
|
|
|
|
// document.querySelectorAll('.btnBranchEdit').forEach(item => {
|
|
// item.addEventListener('click', event => {
|
|
// // Prevent the default action of the link
|
|
// event.preventDefault();
|
|
|
|
// // Get the data-id attribute value of the clicked element
|
|
// const dataId = event.target.getAttribute('data-id');
|
|
|
|
// // Use the data-id value as needed
|
|
// console.log(dataId);
|
|
// });
|
|
// });
|
|
|
|
|
|
$('body').on('click', '#btnSubmit', function() {
|
|
$('#policies_list').html("");
|
|
loadPoliciesList();
|
|
|
|
setTimeout(function() {
|
|
}, 1000) });
|
|
|
|
function loadPoliciesList() {
|
|
var base_url = '<?= base_url("master/policy/policies/list/"); ?>';
|
|
|
|
var insurer_branch_action = base_url + policy_type_PrimaryKey;
|
|
|
|
if ($('#policy_type_id').val() != '') {
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
$.ajax({
|
|
url: insurer_branch_action,
|
|
type: 'GET',
|
|
success: function(response) {
|
|
|
|
console.log("response", response);
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
var branchTable = '';
|
|
$.each(response.policies, function(index, item) {
|
|
console.log(item);
|
|
branchTable += `
|
|
<tr>
|
|
<td value=''>${item.insurer.name}</td>
|
|
<td>${item.policy.name}</td>
|
|
<td>
|
|
<a class="btnBranchEdit" data-id="${item.policy.id}"><i data-id="${item.policy.id}" class="mdi mdi-lead-pencil btnBranchEdit" style="font-size:18px;"></i></a>
|
|
<a style="color:#02a8b5" data-id="${item.id}" onclick="removePolicies(this)"><i data-id="${item.id}" class="mdi mdi-delete" style="font-size:18px;"></i></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
$('#policies_list').append(branchTable);
|
|
},
|
|
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 removePolicies(element) {
|
|
|
|
Swal.fire({
|
|
title: "Are you sure?",
|
|
text: "You need to remove this Policy.",
|
|
icon: "info",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Yes",
|
|
}).then((result) => {
|
|
|
|
if (result.isConfirmed) {
|
|
var policy_id_for_reload = $('#policy_type_id').val()
|
|
var id = element.getAttribute('data-id');
|
|
var form_action = '<?= base_url("master/policy/policies/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('Policy removed successfully', 'Success');
|
|
// $('#branch_table').empty();
|
|
// location.reload();
|
|
window.location.href = '<?= base_url("master/policy/list/") ?>' + policy_id_for_reload;
|
|
|
|
} else {
|
|
toastr.warning('Failed to remove policy', '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 policy', 'Warning');
|
|
}
|
|
});
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
|
|
</script>
|