1030 lines
40 KiB
PHP
Executable File
1030 lines
40 KiB
PHP
Executable File
<style>
|
||
#insurer_datatable {
|
||
width: 100% !important;
|
||
}
|
||
|
||
.table-responsive {
|
||
overflow-x: auto;
|
||
}
|
||
|
||
.truncate {
|
||
max-width: 80px;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
/* Hide dropdown list only for the insurer copy select (search-only UX) */
|
||
#insurer.select2-hidden-accessible + .select2-container .select2-dropdown {
|
||
display: none !important;
|
||
}
|
||
|
||
.select2-container .select2-selection--multiple .select2-selection__choice {
|
||
color: #000000;
|
||
}
|
||
</style>
|
||
|
||
<style>
|
||
#dynamic-form-container {
|
||
overflow-y: auto;
|
||
overflow-x: hidden;
|
||
max-height: 300px;
|
||
}
|
||
|
||
/* Custom scrollbar styles */
|
||
#dynamic-form-container::-webkit-scrollbar {
|
||
width: 8px; /* Set the width of the scrollbar */
|
||
}
|
||
|
||
#dynamic-form-container::-webkit-scrollbar-thumb {
|
||
background-color: #888; /* Color of the scrollbar thumb */
|
||
border-radius: 4px; /* Rounded corners of the scrollbar thumb */
|
||
}
|
||
|
||
#dynamic-form-container::-webkit-scrollbar-thumb:hover {
|
||
background-color: #555; /* Color of the scrollbar thumb on hover */
|
||
}
|
||
|
||
#dynamic-form-container::-webkit-scrollbar-track {
|
||
background-color: #f1f1f1; /* Background color of the scrollbar track */
|
||
}
|
||
|
||
#template_modal {
|
||
padding-right: 0 !important;
|
||
z-index: 1060;
|
||
}
|
||
|
||
#template_modal .select2-container {
|
||
z-index: 1061;
|
||
}
|
||
|
||
#template_modal .select2-dropdown {
|
||
z-index: 1062;
|
||
}
|
||
|
||
#template_modal.show {
|
||
display: flex !important;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.modal-backdrop {
|
||
z-index: 1050;
|
||
}
|
||
</style>
|
||
|
||
<div class="tab-pane fade" id="template-tab" style="padding-left: 25px;">
|
||
|
||
<input type="hidden" id="insurer_templete_count" value="<?= isset($insurer_templete_count) ? $insurer_templete_count : ''?>">
|
||
<input type="hidden" id="insurer_id" value="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>">
|
||
|
||
<div class="row">
|
||
<div class="form-group col-md-4">
|
||
<div class="custom-form">
|
||
<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>
|
||
|
||
<div class="form-group col-md-6" style="position: relative;top: 28px;">
|
||
<label for="email"><span class="text-danger"></span></label>
|
||
<a href="javascript:void(0);" class="btn app-btn-secondary mr-2" onclick="checkInsurerTemplete(this)">Copy</a>
|
||
</div>
|
||
|
||
<div class="form-group col-md-2" style="position: relative;top: 28px;">
|
||
<div class="float-right">
|
||
<label for="email"><span class="text-danger"></span></label>
|
||
<a href="javascript:void(0);" class="btn app-btn-primary" onclick="addNewJsonExportTemplate(this)"><i class="mdi mdi-plus"></i> Add </a>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<div class="table-responsive" id="branch_table" >
|
||
|
||
<table data-custom-table-css="table" class="table table-borderless table-nowrap mb-0 w-100" id="insurer_datatable">
|
||
<thead class="">
|
||
|
||
<tr>
|
||
<th>S.NO </th>
|
||
<th>Policy Type </th>
|
||
<th>Event Type </th>
|
||
<th>Upload/Download </th>
|
||
<th>Template </th>
|
||
<th>Action </th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php if(isset($insurer_templete_list)){ ?>
|
||
<?php foreach($insurer_templete_list as $key => $value ){ ?>
|
||
<tr>
|
||
<td><?= $key+1; ?></td>
|
||
<td><?= $value['policy_type']; ?></td>
|
||
<td><?= $events[$value['event_name']]; ?></td>
|
||
<td><?= $value['type_name'] == 'import' ? 'Upload' : 'Download'; ?></td>
|
||
<td style="overflow: hidden;" class="truncate" ><?= $value['jsoncolumns']; ?></td>
|
||
<td>
|
||
<div class="btn-group dropdown">
|
||
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
|
||
<div class="dropdown-menu dropdown-menu-right">
|
||
<a class="dropdown-item" href="#" onclick="editJSONExportTemplate(this, '<?= $value['id']; ?>')"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
||
<a class="dropdown-item template_id_for_duplicate" data-id="<?= $value['id']; ?>" data-toggle="modal" data-target="#centermodal"><i class="mdi mdi-content-duplicate mr-2 text-muted font-18 vertical-middle"></i>Duplicate</a>
|
||
</div>
|
||
</div>
|
||
</td>
|
||
</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">
|
||
<div class="modal-dialog modal-full-width modal-dialog-centered">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">Create Template</h4>
|
||
<button type="button" id="close_btn" class="close js-template-modal-close" data-dismiss="modal" data-bs-dismiss="modal" aria-hidden="true" onclick="hideTemplateModal()">×</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="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>">
|
||
<input type="hidden" name="template_id" id="template_id">
|
||
<div class="form-group">
|
||
<div class="form-row">
|
||
<div class="form-group col-md-5">
|
||
<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-5">
|
||
<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>
|
||
|
||
<hr class="mb-0">
|
||
|
||
<!-- <div class="form-row dynamic-form-row">
|
||
<div class="form-group col-md-5">
|
||
<label for="excel_column_name">Header Name<span class="text-danger">*</span></label>
|
||
<input class="form-control" type="text" name="excel_column_name[]">
|
||
</div>
|
||
<div class="form-group col-md-5">
|
||
<label for="db_column_name">DataBase Column Name<span class="text-danger">*</span></label>
|
||
<select class="form-control" name="db_column_name[]" required>
|
||
<option selected>Select DB Column</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 id="dynamic-form-container"></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 -->
|
||
|
||
<!-- Center modal content -->
|
||
<div class="modal fade" id="centermodal" tabindex="-1" role="dialog" aria-hidden="true">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">Duplicate Template</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
|
||
<input type="hidden" id="insurer_id_for_dub_temp" value="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>">
|
||
<input type="hidden" id="duplicate_template_id" value="">
|
||
|
||
<div class="form-row">
|
||
|
||
<!-- <div class="form-group col-md-12">
|
||
<label for="event_name">Event<span class="text-danger">*</span></label>
|
||
<select class="form-control" name="event_name_for_duplicate" id="event_name_for_duplicate">
|
||
<option value="">Select</option>
|
||
<option value="inception">Inception</option>
|
||
<option value="addition">Addition</option>
|
||
<option value="dependent_addition">Dependent Addition</option>
|
||
<option value="deletion">Deletion</option>
|
||
<option value="correction">Correction</option>
|
||
<option value="si_enhancement">SI Enhancement</option>
|
||
<option value="si_enhancement">All</option>
|
||
</select>
|
||
</div> -->
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="event_name">Event<span class="text-danger">*</span></label>
|
||
<select name="event_name_for_duplicate" class="form-control" id="event_name_for_duplicate" 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>
|
||
|
||
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
|
||
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="dublicateTemplate(this)">Duplicate</a>
|
||
</div>
|
||
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
<script>
|
||
var insurerTemplateDataTable = null;
|
||
var templateDebugPrefix = '[InsurerTemplate]';
|
||
var insurerDbColumnOptions = <?= json_encode($db_column_name ?? [], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) ?>;
|
||
|
||
function buildDbColumnSelectOptions() {
|
||
var html = '<option value="" selected>Select</option>';
|
||
if (!insurerDbColumnOptions || typeof insurerDbColumnOptions !== 'object') {
|
||
return html;
|
||
}
|
||
Object.keys(insurerDbColumnOptions).forEach(function (label) {
|
||
var value = insurerDbColumnOptions[label];
|
||
html += '<option value="' + String(value).replace(/"/g, '"') + '">' + String(label).replace(/</g, '<') + '</option>';
|
||
});
|
||
return html;
|
||
}
|
||
|
||
function initDbColumnSelect2($select) {
|
||
if (!$select || !$select.length || typeof $.fn.select2 !== 'function') {
|
||
return;
|
||
}
|
||
if ($select.hasClass('select2-hidden-accessible')) {
|
||
$select.select2('destroy');
|
||
}
|
||
$select.select2({
|
||
placeholder: 'Select',
|
||
allowClear: true,
|
||
width: '100%',
|
||
dropdownParent: $('#template_modal')
|
||
});
|
||
}
|
||
|
||
function destroyDbColumnSelect2InContainer(container) {
|
||
var $container = container ? $(container) : $('#dynamic-form-container');
|
||
$container.find('.db-column-name-select').each(function () {
|
||
var $el = $(this);
|
||
if ($el.hasClass('select2-hidden-accessible')) {
|
||
$el.select2('destroy');
|
||
}
|
||
});
|
||
}
|
||
|
||
function showTemplateModal() {
|
||
var $modal = $('#template_modal');
|
||
var modalEl = document.getElementById('template_modal');
|
||
if (!modalEl) {
|
||
return;
|
||
}
|
||
|
||
if (typeof jQuery !== 'undefined' && jQuery.fn && typeof jQuery.fn.modal === 'function') {
|
||
try {
|
||
$modal.modal('show');
|
||
setTimeout(function () {
|
||
if (!$modal.hasClass('show') || !$modal.is(':visible')) {
|
||
forceShowTemplateModal();
|
||
}
|
||
}, 120);
|
||
} catch (e) {
|
||
console.error(templateDebugPrefix + ' jQuery.modal show failed:', e);
|
||
forceShowTemplateModal();
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (window.bootstrap && bootstrap.Modal) {
|
||
if (typeof bootstrap.Modal.getOrCreateInstance === 'function') {
|
||
try {
|
||
bootstrap.Modal.getOrCreateInstance(modalEl).show();
|
||
} catch (e) {
|
||
console.error(templateDebugPrefix + ' bootstrap getOrCreateInstance show failed:', e);
|
||
forceShowTemplateModal();
|
||
}
|
||
return;
|
||
}
|
||
if (typeof bootstrap.Modal.getInstance === 'function') {
|
||
var existing = bootstrap.Modal.getInstance(modalEl);
|
||
if (existing) {
|
||
try {
|
||
existing.show();
|
||
} catch (e) {
|
||
console.error(templateDebugPrefix + ' bootstrap existing show failed:', e);
|
||
forceShowTemplateModal();
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
try {
|
||
(new bootstrap.Modal(modalEl)).show();
|
||
return;
|
||
} catch (e) {
|
||
console.error(templateDebugPrefix + ' bootstrap constructor show failed:', e);
|
||
forceShowTemplateModal();
|
||
return;
|
||
}
|
||
}
|
||
|
||
forceShowTemplateModal();
|
||
}
|
||
|
||
function forceShowTemplateModal() {
|
||
var modalEl = document.getElementById('template_modal');
|
||
if (!modalEl) {
|
||
return;
|
||
}
|
||
|
||
modalEl.style.display = 'block';
|
||
modalEl.classList.add('show');
|
||
modalEl.removeAttribute('aria-hidden');
|
||
modalEl.setAttribute('aria-modal', 'true');
|
||
document.body.classList.add('modal-open');
|
||
|
||
if (!document.querySelector('.modal-backdrop')) {
|
||
var backdrop = document.createElement('div');
|
||
backdrop.className = 'modal-backdrop fade show';
|
||
document.body.appendChild(backdrop);
|
||
}
|
||
}
|
||
|
||
function hideTemplateModal() {
|
||
var $modal = $('#template_modal');
|
||
var modalEl = document.getElementById('template_modal');
|
||
if (!modalEl) {
|
||
return;
|
||
}
|
||
|
||
var closed = false;
|
||
try {
|
||
if (typeof jQuery !== 'undefined' && jQuery.fn && typeof jQuery.fn.modal === 'function') {
|
||
$modal.modal('hide');
|
||
closed = true;
|
||
}
|
||
if (!closed && window.bootstrap && bootstrap.Modal) {
|
||
if (typeof bootstrap.Modal.getOrCreateInstance === 'function') {
|
||
bootstrap.Modal.getOrCreateInstance(modalEl).hide();
|
||
closed = true;
|
||
}
|
||
if (!closed && typeof bootstrap.Modal.getInstance === 'function') {
|
||
var existing = bootstrap.Modal.getInstance(modalEl);
|
||
if (existing) {
|
||
existing.hide();
|
||
closed = true;
|
||
}
|
||
}
|
||
if (!closed) {
|
||
(new bootstrap.Modal(modalEl)).hide();
|
||
closed = true;
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error(templateDebugPrefix + ' hide modal failed:', e);
|
||
}
|
||
|
||
if (!closed || modalEl.classList.contains('show')) {
|
||
forceHideTemplateModal();
|
||
}
|
||
}
|
||
|
||
function forceHideTemplateModal() {
|
||
var modalEl = document.getElementById('template_modal');
|
||
if (!modalEl) {
|
||
return;
|
||
}
|
||
|
||
modalEl.classList.remove('show');
|
||
modalEl.style.display = 'none';
|
||
modalEl.setAttribute('aria-hidden', 'true');
|
||
modalEl.removeAttribute('aria-modal');
|
||
document.body.classList.remove('modal-open');
|
||
document.body.style.removeProperty('padding-right');
|
||
$('.modal-backdrop').remove();
|
||
}
|
||
|
||
function initInsurerTemplateDataTable() {
|
||
if ($.fn.DataTable.isDataTable('#insurer_datatable')) {
|
||
$('#insurer_datatable').DataTable().destroy();
|
||
}
|
||
insurerTemplateDataTable = $('#insurer_datatable').DataTable({
|
||
paging: true,
|
||
searching: true,
|
||
autoWidth: false,
|
||
scrollX: false,
|
||
responsive: false,
|
||
language: {
|
||
emptyTable: "No template data available"
|
||
}
|
||
});
|
||
}
|
||
|
||
$(document).ready(function(){
|
||
$('#insurer').select2();
|
||
// $('#event').select2();
|
||
featchInsurerList();
|
||
initInsurerTemplateDataTable();
|
||
$('a[data-toggle="tab"], a[data-bs-toggle="tab"]').on('shown.bs.tab', function () {
|
||
if ($.fn.DataTable.isDataTable('#insurer_datatable')) {
|
||
$('#insurer_datatable').DataTable().columns.adjust();
|
||
}
|
||
});
|
||
$(document).on('click', '.template_id_for_duplicate', function() {
|
||
$('#duplicate_template_id').val($(this).data('id'));
|
||
});
|
||
|
||
})
|
||
|
||
$('#templateForm').submit(function(event) {
|
||
|
||
event.preventDefault();
|
||
|
||
var jsonString = createFormArray();; // Convert the array to a JSON string
|
||
console.log(jsonString);
|
||
|
||
var formData = new FormData($('#templateForm')[0]);
|
||
var url = '<?= base_url("util/create_excel_template") ?>';
|
||
|
||
formData.append('json_data', jsonString);
|
||
|
||
$.ajax({
|
||
url: url,
|
||
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('Export template list:', response);
|
||
|
||
if(response.status == false){
|
||
toastr.error(response.message,'Error');
|
||
}else{
|
||
toastr.success(response.message,'Success');
|
||
}
|
||
|
||
window.location.reload();
|
||
},
|
||
error: function (xhr, status, error) {
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
// Detailed error handling
|
||
console.error("Request failed with status: " + status + ", error: " + error);
|
||
|
||
// Log detailed response information
|
||
console.error('Response status code:', xhr.status);
|
||
console.error('Response status text:', xhr.statusText);
|
||
console.error('Response readyState:', xhr.readyState);
|
||
console.error('Response text:', xhr.responseText);
|
||
|
||
// Optionally log additional details
|
||
console.error('Response headers:', xhr.getAllResponseHeaders());
|
||
console.error('Response URL:', xhr.responseURL);
|
||
|
||
if (xhr.status === 400) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
let errorMessages = "";
|
||
let seenMessages = []; // Array to store unique messages
|
||
if (response.errors) {
|
||
$.each(response.errors, function (field, message) {
|
||
if (!seenMessages.includes(message)) {
|
||
errorMessages += `• ${message}<br>`;
|
||
seenMessages.push(message); // Mark this message as "seen"
|
||
}
|
||
});
|
||
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
||
} else {
|
||
toastr.warning(response.message || 'Validation failed', 'Warning');
|
||
}
|
||
|
||
} else if (xhr.status === 403) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
toastr.error(response.message, 'Security Policy');
|
||
} else if (xhr.status === 500) {
|
||
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
||
} else {
|
||
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
||
}
|
||
|
||
// Fallback
|
||
toastr.error('Unexpected error occurred.', 'Error');
|
||
},
|
||
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)
|
||
{
|
||
var insurer_id = $('#insurer_id').val();
|
||
console.log('insurer_id', insurer_id);
|
||
$('#insurer').empty();
|
||
$('#insurer').append($('<option>', {
|
||
value: '',
|
||
text: 'Select',
|
||
selected: true
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
if(insurer_id != item.id){
|
||
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)
|
||
{
|
||
if (input && input.preventDefault) {
|
||
input.preventDefault();
|
||
}
|
||
$('#myCenterModalLabel').text('Create Template');
|
||
destroyDbColumnSelect2InContainer();
|
||
$('#dynamic-form-container').empty();
|
||
addHTMLInput();
|
||
showTemplateModal();
|
||
}
|
||
|
||
function addHTMLInput(element = null, data = null)
|
||
{
|
||
const container = document.getElementById('dynamic-form-container');
|
||
const newRow = document.createElement('div');
|
||
newRow.className = 'form-row dynamic-form-row';
|
||
const disableDbSelect = data !== null && data !== undefined && data !== '' && data.default_value != "" && data.default_value != null;
|
||
const headerValue = data !== null && data !== undefined && data !== '' ? (data.column_name || '') : '';
|
||
const defaultValue = data != null && data != undefined && data != '' && data.default_value != "" && data.default_value != null ? data.default_value : '';
|
||
|
||
newRow.innerHTML = `
|
||
<div class="mt-3 p-3" style="width: 100%; background: #F7F7F7;
|
||
border-radius: 30px !important;
|
||
display: flex;
|
||
gap: 10px;
|
||
opacity: 1;
|
||
">
|
||
<div class="form-group col-md-3">
|
||
<label for="db_column_name">DataBase Column Name<span class="text-danger"></span></label>
|
||
<select class="form-control db-column-name-select" name="db_column_name[]" onchange="checkForDuplicates(this); handleDbColumnChange(this)"${disableDbSelect ? ' disabled' : ''}>
|
||
${buildDbColumnSelectOptions()}
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="excel_column_name">Header Name<span class="text-danger">*</span></label>
|
||
<input id="excel_column_name" value="${headerValue}" class="form-control" type="text" name="excel_column_name[]" placeholder="Excel Header Column Name">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="default_value">Default Value<span class="text-danger"></span></label>
|
||
<input id="default_value" value="${defaultValue}" class="form-control" type="text" name="default_value[]" placeholder="Excel Default value">
|
||
</div>
|
||
|
||
<div class="form-group col-md-2" style="position: relative;left: 28px;">
|
||
<a class="btn app-btn-secondary waves-effect waves-light mr-1" onclick="addHTMLInput(this)"><i class="mdi mdi-plus text-white" style="cursor:pointer; font-size:15px !important;"></i></a>
|
||
<a class="btn btn-danger waves-effect waves-light" onclick="removeHTMLInput(this)"><i class="mdi mdi-trash-can text-white" style="cursor:pointer; font-size:15px !important;"></i></a>
|
||
</div>
|
||
</div>
|
||
`;
|
||
container.appendChild(newRow);
|
||
var $dbSelect = $(newRow).find('.db-column-name-select');
|
||
if (data != null && data.db_column_name != undefined) {
|
||
$dbSelect.val(data.db_column_name);
|
||
}
|
||
initDbColumnSelect2($dbSelect);
|
||
if (data != null && data.db_column_name != undefined) {
|
||
$dbSelect.trigger('change');
|
||
}
|
||
}
|
||
|
||
// function removeHTMLInput(element)
|
||
// {
|
||
// const row = element.closest('.dynamic-form-row');
|
||
// row.remove();
|
||
// }
|
||
|
||
|
||
function removeHTMLInput(element)
|
||
{
|
||
const container = document.getElementById('dynamic-form-container');
|
||
const rows = container.querySelectorAll('.dynamic-form-row');
|
||
|
||
if (rows.length > 1) {
|
||
const row = element.closest('.dynamic-form-row');
|
||
$(row).find('.db-column-name-select').each(function () {
|
||
var $el = $(this);
|
||
if ($el.hasClass('select2-hidden-accessible')) {
|
||
$el.select2('destroy');
|
||
}
|
||
});
|
||
row.remove();
|
||
}
|
||
}
|
||
|
||
function createFormArray()
|
||
{
|
||
var formArray = [];
|
||
|
||
try {
|
||
var columnNames = $('input[name="excel_column_name[]"]');
|
||
var defaultValues = $('input[name="default_value[]"]');
|
||
var dbColumnNames = $('select[name="db_column_name[]"]');
|
||
|
||
// Check if both arrays are of the same length
|
||
if (columnNames.length !== dbColumnNames.length) {
|
||
throw new Error('Mismatch between the number of column names and database column names.');
|
||
}
|
||
|
||
// Iterate over the column names and build the formArray
|
||
columnNames.each(function(index) {
|
||
var columnName = $(this).val();
|
||
var dbColumnName = dbColumnNames.eq(index).val() ?? null;
|
||
var defaultValue = defaultValues.eq(index).val() ?? null;
|
||
|
||
// if (!columnName) {
|
||
// throw new Error(`Column name at index ${index} is empty.`);
|
||
// }
|
||
// if (!dbColumnName) {
|
||
// throw new Error(`Database column name at index ${index} is empty.`);
|
||
// }
|
||
|
||
var columnObj = {
|
||
'column_index': index,
|
||
'column_name': columnName,
|
||
'db_column_name': dbColumnName,
|
||
'default_value': defaultValue
|
||
};
|
||
formArray.push(columnObj);
|
||
});
|
||
|
||
console.log('Form array successfully created:', formArray);
|
||
var jsonString = JSON.stringify(formArray);
|
||
console.log('Form array successfully created: jsonString', jsonString);
|
||
return jsonString;
|
||
|
||
} catch (error) {
|
||
console.error('Error creating form array:', error.message);
|
||
// Optionally, display an error message to the user
|
||
alert('An error occurred while processing the form: ' + error.message);
|
||
return null; // Return null to indicate that an error occurred
|
||
}
|
||
}
|
||
|
||
function editJSONExportTemplate(input, id)
|
||
{
|
||
console.log(id);
|
||
$('#template_id').val(id);
|
||
$('#myCenterModalLabel').text('Edit Template');
|
||
var url = '<?php echo base_url('util/get_single_excel_template/'); ?>' + id;
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
$.ajax({
|
||
url: url,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.log('editJSONExportTemplate response', res)
|
||
|
||
$('#policy_type').val(res.data.policy_type_id);
|
||
$('#event').val(res.data.event_name);
|
||
|
||
// console.log(res.data.jsoncolumns);
|
||
var data = JSON.parse(res.data.jsoncolumns)
|
||
// console.log(JSON.parse(res.data.jsoncolumns));
|
||
|
||
destroyDbColumnSelect2InContainer();
|
||
$('#dynamic-form-container').empty();
|
||
|
||
$.each(data, function(index, item) {
|
||
|
||
addHTMLInput(null, item)
|
||
|
||
});
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
|
||
showTemplateModal();
|
||
}
|
||
|
||
function checkForDuplicates(selectElement)
|
||
{
|
||
|
||
const selectedValue = selectElement.value;
|
||
const selects = document.querySelectorAll('#dynamic-form-container .db-column-name-select');
|
||
|
||
let isDuplicate = false;
|
||
|
||
selects.forEach(select => {
|
||
if (select !== selectElement && select.value === selectedValue) {
|
||
isDuplicate = true;
|
||
}
|
||
});
|
||
|
||
// if (isDuplicate) {
|
||
// toastr.warning('This value is already selected in another dropdown.', 'Warning');
|
||
// selectElement.value = '';
|
||
// }
|
||
}
|
||
|
||
$('.close').click(function()
|
||
{
|
||
destroyDbColumnSelect2InContainer();
|
||
$('#dynamic-form-container').empty();
|
||
$('#policy_type').val('');
|
||
$('#event').val('').change();
|
||
$('#excel_column_name').val('');
|
||
$('#template_id').val('')
|
||
});
|
||
|
||
function dublicateTemplate()
|
||
{
|
||
var template_id = $('#duplicate_template_id').val();
|
||
var event_name = $('#event_name_for_duplicate').val();
|
||
var insurer_id = $('#insurer_id_for_dub_temp').val();
|
||
|
||
if (template_id === "") {
|
||
toastr.warning('Please select a template to duplicate.', 'Warning');
|
||
return false;
|
||
}
|
||
|
||
console.log('template_id_for_duplicate', template_id)
|
||
console.log('event_name_for_duplicate', event_name)
|
||
console.log('insurer_id', insurer_id)
|
||
|
||
if(event_name == ""){
|
||
|
||
Swal.fire({
|
||
title: "warning!",
|
||
text: 'Please select the Event',
|
||
icon: "warning"
|
||
});
|
||
|
||
return false
|
||
}
|
||
|
||
var url = '<?= base_url('util/dublicate_template/') ?>' + template_id + '/' + event_name + '/' +insurer_id
|
||
|
||
$.ajax({
|
||
url: url,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
|
||
console.log('dublicateTemplate 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');
|
||
}
|
||
});
|
||
}
|
||
|
||
$(document).on('input', 'input[name="default_value[]"]', function () {
|
||
let $defaultInput = $(this);
|
||
let $row = $defaultInput.closest('.form-row, .row'); // Adjust based on your actual container
|
||
let $dbSelect = $row.find('select[name="db_column_name[]"]');
|
||
|
||
if ($defaultInput.val().trim() !== '') {
|
||
$dbSelect.val(null).trigger('change').prop('disabled', true);
|
||
} else {
|
||
$dbSelect.prop('disabled', false).trigger('change');
|
||
}
|
||
});
|
||
|
||
function handleDbColumnChange(element) {
|
||
console.log('=== SELECT CHANGE EVENT TRIGGERED ===');
|
||
|
||
let $defaultInput = $(element);
|
||
console.log('1. Current select element:', $defaultInput);
|
||
console.log('2. Current select value:', $defaultInput.val());
|
||
|
||
let $row = $defaultInput.closest('.form-row, .row');
|
||
console.log('3. Found row element:', $row);
|
||
console.log('4. Row exists:', $row.length > 0);
|
||
|
||
// Updated to find input instead of select for excel_column_name
|
||
let $excelInput = $row.find('input[name="excel_column_name[]"]');
|
||
console.log('5. Target input element:', $excelInput);
|
||
console.log('6. Target input exists:', $excelInput.length > 0);
|
||
console.log('7. Current target input value:', $excelInput.val());
|
||
|
||
// Get the selected option's text (the display text, not the value)
|
||
let selectedText = $defaultInput.find('option:selected').text().trim();
|
||
console.log('8. Selected option text:', selectedText);
|
||
console.log('9. Selected text length:', selectedText.length);
|
||
|
||
// Also get the selected value for comparison
|
||
let selectedValue = $defaultInput.val();
|
||
console.log('10. Selected option value:', selectedValue);
|
||
|
||
if (selectedText !== '' && selectedText !== 'Select') {
|
||
console.log('11. Setting target input value to:', selectedText);
|
||
$excelInput.val(selectedText);
|
||
console.log('12. Target input value after setting:', $excelInput.val());
|
||
} else {
|
||
console.log('11. Selected text is empty or "Select", clearing target input');
|
||
// $excelInput.val("");
|
||
console.log('12. Target input value after clearing:', $excelInput.val());
|
||
}
|
||
|
||
console.log('=== EVENT HANDLING COMPLETE ===');
|
||
}
|
||
|
||
</script>
|