152 lines
4.4 KiB
PHP
152 lines
4.4 KiB
PHP
<div class="tab-pane fade" id="template-tab">
|
|
|
|
<input type="hidden" id="insurer_templete_count" value="<?= isset($insurer_templete_count) ? $insurer_templete_count : ''?>">
|
|
<div class="row">
|
|
<div class="form-group col-md-4">
|
|
<label for="email">Existing Insurer Export<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="insurer" name="insurer" required>
|
|
<option value="">Select Insurer</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3" style="position: relative;top: 28px;">
|
|
<label for="email"><span class="text-danger"></span></label>
|
|
<a href="#" class="btn btn-primary waves-effect waves-light" onclick="checkInsurerTemplete(this)">Copy</a>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
$('#insurer').select2();
|
|
featchInsurerList()
|
|
})
|
|
|
|
function featchInsurerList()
|
|
{
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("util/get_insurer_by_export_templete") ?>',
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
console.log('featchInsurerList list', res)
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
appendInsurer(res.data)
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
function appendInsurer(data)
|
|
{
|
|
|
|
$('#insurer').empty();
|
|
$('#insurer').append($('<option>', {
|
|
value: '',
|
|
text: 'Select',
|
|
selected: true
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.insurer_name
|
|
});
|
|
$('#insurer').append(option);
|
|
});
|
|
|
|
}
|
|
|
|
function checkInsurerTemplete(input)
|
|
{
|
|
var existing_insurer_id = $('#insurer').val();
|
|
var copy_insurer_id = $('#insurer_General_PrimaryKey').val()
|
|
var insurer_templete_count = $('#insurer_templete_count').val()
|
|
|
|
if(existing_insurer_id == '')
|
|
{
|
|
Swal.fire({
|
|
title: "warning!",
|
|
text: 'Please select the Insurer',
|
|
icon: "warning"
|
|
});
|
|
return false;
|
|
}
|
|
|
|
console.log('existing_insurer_id', existing_insurer_id)
|
|
console.log('copy_insurer_id', copy_insurer_id)
|
|
console.log('insurer_templete_count', insurer_templete_count)
|
|
|
|
$('#insurer').val('').change();
|
|
|
|
if(insurer_templete_count == 0){
|
|
copyTemplateAJAX(existing_insurer_id, copy_insurer_id)
|
|
|
|
}else{
|
|
|
|
Swal.fire({
|
|
title: "The insurer already have export template?",
|
|
text: "If you want to approve this the existing template will be deleted!",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Yes",
|
|
}).then((result) => {
|
|
|
|
|
|
if (result.isConfirmed) {
|
|
copyTemplateAJAX(existing_insurer_id, copy_insurer_id)
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function copyTemplateAJAX(existing_insurer_id, copy_insurer_id)
|
|
{
|
|
$.ajax({
|
|
url: '<?= base_url("util/copy_insurer_templete/") ?>' + existing_insurer_id + '/' + copy_insurer_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
console.log('checkInsurerTemplete response', res)
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
if(res.status == false){
|
|
toastr.error(res.message, 'ERROR');
|
|
}else{
|
|
toastr.success(res.message, 'SUCCESS');
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}
|
|
});
|
|
}
|
|
|
|
</script> |