FEAT_CHECK_DUBLICAT
This commit is contained in:
parent
410c7d0c6c
commit
d6db9f3541
@ -783,5 +783,6 @@ $routes->group('commission', function($routes) {
|
|||||||
$routes->get('sample_file',"RuleImportController::downloadSampleCommissionFileUploadExcel");
|
$routes->get('sample_file',"RuleImportController::downloadSampleCommissionFileUploadExcel");
|
||||||
$routes->get('downloadErrorFile',"RuleImportController::downloadErrorFile");
|
$routes->get('downloadErrorFile',"RuleImportController::downloadErrorFile");
|
||||||
$routes->get("deleteCommissionData/(:any)", "RuleImportController::deleteCommissionData/$1");
|
$routes->get("deleteCommissionData/(:any)", "RuleImportController::deleteCommissionData/$1");
|
||||||
|
$routes->get('checkSameEntry',"RuleImportController::checkSameEntry");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -102,6 +102,7 @@ class RuleImportController extends AdminController
|
|||||||
$insurerId = $this->request->getPost('insurer_id');
|
$insurerId = $this->request->getPost('insurer_id');
|
||||||
$department = $this->request->getPost('department');
|
$department = $this->request->getPost('department');
|
||||||
$commissionMonth = $this->request->getPost('commission_month');
|
$commissionMonth = $this->request->getPost('commission_month');
|
||||||
|
$overwrite = $this->request->getPost('overwrite') ?? 0;
|
||||||
$createdBy = get_session_userid();
|
$createdBy = get_session_userid();
|
||||||
|
|
||||||
if (empty($insurerId) || empty($department) || empty($commissionMonth)) {
|
if (empty($insurerId) || empty($department) || empty($commissionMonth)) {
|
||||||
@ -424,5 +425,19 @@ class RuleImportController extends AdminController
|
|||||||
return $this->respond(['status' => true, 'code' => 200, 'message' => "File removed successfully"], 200);
|
return $this->respond(['status' => true, 'code' => 200, 'message' => "File removed successfully"], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkSameEntry()
|
||||||
|
{
|
||||||
|
$data = $this->request->getGet();
|
||||||
|
$commissionMonth = $data['commission_month'] . '-01';
|
||||||
|
$data['commission_month'] = change_date_format($commissionMonth, 'Y-M-d', 'Y-m-d');
|
||||||
|
|
||||||
|
$count = $this->commissionFilesModel->where($data)->where('is_active', 1)->countAllResults();
|
||||||
|
if($count > 0){
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $count, 'message' => ""], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => false, 'code' => 404, 'data' => $count, 'message' => ""], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -217,7 +217,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="insurer"> Insurer <spanclass="text-danger">*</spanclass=></label>
|
<label for="insurer"> Insurer <spanclass="text-danger">*</spanclass=></label>
|
||||||
<select class="form-control" id="insurer_id" name="insurer_id" required>
|
<select class="form-control" id="insurer_id" name="insurer_id" onchange="checkSameEntry(this)" required>
|
||||||
<option value="" selected>Select Insurer</option>
|
<option value="" selected>Select Insurer</option>
|
||||||
<?php
|
<?php
|
||||||
if (isset($insurers) && count($insurers)) {
|
if (isset($insurers) && count($insurers)) {
|
||||||
@ -230,13 +230,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="statement_month">Commission Month</label>
|
<label for="statement_month">Commission Month</label>
|
||||||
<input type="text" class="form-control" id="commission_month" name="commission_month" placeholder="" required readonly>
|
<input type="text" class="form-control" id="commission_month" name="commission_month" onchange="checkSameEntry(this)" placeholder="" required readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="statement_no">Department</label>
|
<label for="statement_no">Department</label>
|
||||||
<select class="form-control" id="department" name="department" required>
|
<select class="form-control" id="department" name="department" onchange="checkSameEntry(this)" required>
|
||||||
<option value="" selected>Select Department</option>
|
<option value="" selected>Select Department</option>
|
||||||
<?php
|
<?php
|
||||||
if (isset($departments) && count($departments)) {
|
if (isset($departments) && count($departments)) {
|
||||||
@ -275,6 +275,8 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
let isDublicateFound = false;
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
const table = document.getElementById("tickets-table");
|
const table = document.getElementById("tickets-table");
|
||||||
|
|
||||||
@ -466,62 +468,91 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#btnSubmit').prop('disabled', true).text('Submitting...');
|
|
||||||
|
|
||||||
// Create FormData object
|
// Create FormData object
|
||||||
var formData = new FormData($(this)[0]);
|
var formData = new FormData($(this)[0]);
|
||||||
|
|
||||||
$('.loader').fadeIn();
|
// FUNCTION to actually submit AJAX
|
||||||
$('.loader-mask').fadeIn();
|
function submitAjax(formData) {
|
||||||
|
$('#btnSubmit').prop('disabled', true).text('Submitting...');
|
||||||
|
$('.loader').fadeIn();
|
||||||
|
$('.loader-mask').fadeIn();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: $(this).attr("action"),
|
url: $('#commission_upload_form').attr("action"),
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: formData,
|
data: formData,
|
||||||
processData: false, // Prevent jQuery from automatically processing the data
|
processData: false,
|
||||||
contentType: false, // Let jQuery handle the content type
|
contentType: false,
|
||||||
headers: {
|
headers: {
|
||||||
// "Content-Type":"multipart/form-data",
|
"X-Requested-With": "XMLHttpRequest"
|
||||||
"X-Requested-With": "XMLHttpRequest"
|
},
|
||||||
},
|
success: function(response) {
|
||||||
success: function(response) {
|
|
||||||
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
$('#commission_upload_form')[0].reset();
|
$('#commission_upload_form')[0].reset();
|
||||||
|
|
||||||
|
if (response.code === 200 && response.status === true) {
|
||||||
|
toastr.success('File upload success', 'SUCCESS');
|
||||||
|
} else if (response.code === 404 && response.status === false) {
|
||||||
|
toastr.error(response.message, 'FAILED');
|
||||||
|
} else {
|
||||||
|
toastr.error('Something went wrong! Try later', 'ERROR');
|
||||||
|
}
|
||||||
|
|
||||||
if (response.code === 200 && response.status === true) {
|
|
||||||
toastr.success('File upload successs','SUCCESS');
|
|
||||||
$('.close').click();
|
$('.close').click();
|
||||||
window.location.reload(true);
|
$('.loader').fadeOut();
|
||||||
} else if (response.code === 404 && response.status === false) {
|
$('.loader-mask').delay(10).fadeOut('slow');
|
||||||
console.error('no data found', response);
|
|
||||||
toastr.error(response.message, 'FAILED');
|
$('#btnSubmit').prop('disabled', false).text('Submit');
|
||||||
window.location.reload(true);
|
|
||||||
} else {
|
window.location.reload(true);
|
||||||
console.error('Something went wrong!');
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error("Request failed:", status, error);
|
||||||
toastr.error('Something went wrong! Try later', 'ERROR');
|
toastr.error('Something went wrong! Try later', 'ERROR');
|
||||||
window.location.reload(true);
|
|
||||||
|
$('.close').click();
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(10).fadeOut('slow');
|
||||||
|
|
||||||
|
$('#btnSubmit').prop('disabled', false).text('Submit');
|
||||||
|
|
||||||
|
window.location.reload(true);
|
||||||
}
|
}
|
||||||
$('.close').click()
|
});
|
||||||
$('.loader').fadeOut();
|
}
|
||||||
$('.loader-mask').delay(10).fadeOut('slow');
|
|
||||||
|
|
||||||
$('#btnSubmit').prop('disabled', false).text('Submit');
|
// Duplicate check
|
||||||
|
if (isDublicateFound) {
|
||||||
|
Swal.fire({
|
||||||
|
title: "Duplicate found. What do you want?",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Overwrite",
|
||||||
|
cancelButtonText: "Append",
|
||||||
|
confirmButtonColor: "#ff3333",
|
||||||
|
}).then((result) => {
|
||||||
|
|
||||||
},
|
if (result.isConfirmed) {
|
||||||
error: function(xhr, status, error) {
|
formData.append('overwrite', 1);
|
||||||
// Request failed, handle error
|
} else {
|
||||||
console.error("Request failed:", status, error);
|
formData.append('overwrite', 0);
|
||||||
toastr.error('Something went wrong! Try later', 'Error');
|
}
|
||||||
$('.close').click()
|
|
||||||
$('.loader').fadeOut();
|
isDublicateFound = false;
|
||||||
$('.loader-mask').delay(10).fadeOut('slow');
|
|
||||||
window.location.reload(true);
|
// 🔥 Continue with form submission AFTER append
|
||||||
}
|
submitAjax(formData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no duplicate, submit normally
|
||||||
|
submitAjax(formData);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// open the file upload modal
|
// open the file upload modal
|
||||||
function showFileUploadModal(input) {
|
function showFileUploadModal(input) {
|
||||||
var myModal = new bootstrap.Modal(document.getElementById('file_upload'));
|
var myModal = new bootstrap.Modal(document.getElementById('file_upload'));
|
||||||
@ -587,4 +618,41 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// avoid dublicate entry
|
||||||
|
function checkSameEntry()
|
||||||
|
{
|
||||||
|
|
||||||
|
let insurer_id = $('#insurer_id').val()
|
||||||
|
let commission_month = $('#commission_month').val()
|
||||||
|
let department = $('#department').val()
|
||||||
|
|
||||||
|
let url = '<?= base_url('commission/checkSameEntry') ?>';
|
||||||
|
|
||||||
|
// Data to send in the AJAX request
|
||||||
|
let requestData = {
|
||||||
|
insurer_id: insurer_id,
|
||||||
|
commission_month: commission_month,
|
||||||
|
department: department,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send AJAX request
|
||||||
|
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||||||
|
|
||||||
|
console.log('Data fetched successfully:', response);
|
||||||
|
|
||||||
|
if (response.status == true) {
|
||||||
|
isDublicateFound = true;
|
||||||
|
}else{
|
||||||
|
isDublicateFound = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, function(xhr, status, error) {
|
||||||
|
isDublicateFound = false;
|
||||||
|
console.error('Error fetching data:', error);
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
console.log('An error occurred while fetching the data.', 'ERROR');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user