348 lines
14 KiB
PHP
348 lines
14 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-6" 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 class="form-group col-md-2" style="position: relative;top: 28px;left: 80px;">
|
||
<label for="email"><span class="text-danger"></span></label>
|
||
<a href="#" class="btn btn-primary waves-effect waves-light" onclick="addNewJsonExportTemplate(this)">Add New</a>
|
||
</div> -->
|
||
|
||
</div>
|
||
|
||
<hr>
|
||
|
||
<div class="table-responsive" id="branch_table" >
|
||
|
||
<table class="table table-borderless table-nowrap mb-0">
|
||
<thead class="thead-light">
|
||
<tr>
|
||
<th>S.NO</th>
|
||
<th>Policy Type</th>
|
||
<th>Event Type</th>
|
||
<th>Import/Export</th>
|
||
<th>Template</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php if(isset($insurer_templete_list)){ ?>
|
||
<?php foreach($insurer_templete_list as $key => $value ){ ?>
|
||
<tr>
|
||
<th><?= $key+1; ?></th>
|
||
<th><?= $value['policy_type']; ?></th>
|
||
<th><?= $value['event_name']; ?></th>
|
||
<th><?= $value['type_name']; ?></th>
|
||
<th><?= $value['jsoncolumns']; ?></th>
|
||
</tr>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Center modal content -->
|
||
<div class="modal fade" id="template_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
|
||
aria-hidden="true" aria-modal="true" data-backdrop="static" style="padding-right: 15px">
|
||
<div class="modal-dialog modal-full-width">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">New Template</h4>
|
||
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="parsley-examples" method="post" id="templateForm" enctype="multipart/form-data">
|
||
<input type="hidden" name="insurer_id" value="<?= $insurer['id'] ?>">
|
||
<div class="form-group">
|
||
<div class="form-row">
|
||
<div class="form-group col-md-4">
|
||
<label for="policy_type">Policy Type<span class="text-danger">*</span></label>
|
||
<select name="policy_type" class="form-control" id="policy_type" required>
|
||
<option value="">Select</option>
|
||
<?php if (!empty($policy_type)){ ?>
|
||
<?php foreach ($policy_type as $key => $value) { ?>
|
||
<option value="<?= $value['id'] ?>"><?= $value['policy_type']?></option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
<div class="form-group col-md-4">
|
||
<label for="event_name">Event<span class="text-danger">*</span></label>
|
||
<select name="event" class="form-control" id="event" required>
|
||
<option value="">Select</option>
|
||
<?php if (!empty($events)){ ?>
|
||
<?php foreach ($events as $key => $event) { ?>
|
||
<option value="<?= $key ?>"><?= $event?></option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
<div class="form-group col-md-4">
|
||
<label for="action">Action<span class="text-danger">*</span></label>
|
||
<select name="import_or_export" class="form-control" id="import_or_export" required>
|
||
<option value="">Select</option>
|
||
<?php if (!empty($action)){ ?>
|
||
<?php foreach ($action as $key => $value) { ?>
|
||
<option value="<?= $key ?>"><?= $value?></option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="dynamic-form-container">
|
||
<div class="form-row dynamic-form-row">
|
||
<div class="form-group col-md-5">
|
||
<label for="header_name">Header Name<span class="text-danger">*</span></label>
|
||
<input class="form-control" type="text" name="header_name[]">
|
||
</div>
|
||
<div class="form-group col-md-5">
|
||
<label for="policy_id">DataBase Column Name<span class="text-danger">*</span></label>
|
||
<select class="form-control" name="policy_id[]" required>
|
||
<option selected>Select Client Policy</option>
|
||
<?php if (!empty($db_column_name)){ ?>
|
||
<?php foreach ($db_column_name as $key => $value) { ?>
|
||
<option value="<?= $value ?>"><?= $key ?></option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
<div class="form-group col-md-2" style="position: relative;top: 28px;">
|
||
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="addHTMLInput(this)">+</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
|
||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
|
||
<script>
|
||
|
||
$(document).ready(function(){
|
||
$('#insurer').select2();
|
||
featchInsurerList()
|
||
})
|
||
|
||
$('#templateForm').submit(function(){
|
||
|
||
event.preventDefault();
|
||
|
||
$.ajax({
|
||
url: $(this).attr("action"),
|
||
type: 'POST',
|
||
data: formData,
|
||
processData: false,
|
||
contentType: false,
|
||
headers: {
|
||
"X-Requested-With": "XMLHttpRequest"
|
||
},
|
||
beforeSend: function() {
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
},
|
||
success: function(response) {
|
||
|
||
console.log('Expoer template list:', response);
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Request failed, handle error
|
||
console.error("Request failed:", status, error);
|
||
console.error('Response:', xhr.responseText);
|
||
},
|
||
complete: function() {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
|
||
});
|
||
|
||
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');
|
||
}
|
||
|
||
window.location.reload(true);
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
}
|
||
|
||
function addNewJsonExportTemplate(input)
|
||
{
|
||
var myModal = new bootstrap.Modal(document.getElementById('template_modal'));
|
||
myModal.show();
|
||
}
|
||
|
||
function addHTMLInput(element)
|
||
{
|
||
const container = document.getElementById('dynamic-form-container');
|
||
const newRow = document.createElement('div');
|
||
newRow.className = 'form-row dynamic-form-row';
|
||
newRow.innerHTML = `
|
||
<div class="form-group col-md-5">
|
||
<label for="header_name">Header Name<span class="text-danger">*</span></label>
|
||
<input class="form-control" type="text" name="header_name[]">
|
||
</div>
|
||
<div class="form-group col-md-5">
|
||
<label for="policy_id">DataBase Column Name<span class="text-danger">*</span></label>
|
||
<select class="form-control" name="db_column_name[]" required>
|
||
<option selected>Select Client Policy</option>
|
||
<?php if (!empty($db_column_name)){ ?>
|
||
<?php foreach ($db_column_name as $key => $value) { ?>
|
||
<option value="<?= $value ?>"><?= $key ?></option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
<div class="form-group col-md-2" style="position: relative;top: 28px;">
|
||
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="addHTMLInput(this)">+</a>
|
||
<a class="btn btn-danger waves-effect waves-light" onclick="removeHTMLInput(this)">x</a>
|
||
</div>
|
||
`;
|
||
container.appendChild(newRow);
|
||
}
|
||
|
||
function removeHTMLInput(element)
|
||
{
|
||
const row = element.closest('.dynamic-form-row');
|
||
row.remove();
|
||
}
|
||
|
||
</script>
|