FIX_LIVE_ISSUE
This commit is contained in:
parent
21594469bc
commit
eb3d58c69a
@ -15,6 +15,7 @@ use App\Controllers\MediAssistApiController;
|
||||
use App\Controllers\FhplApiController;
|
||||
use App\Controllers\VoloApiController;
|
||||
use App\Models\BatchFileModel;
|
||||
use App\Models\ClaimFilesModel;
|
||||
use App\Models\FileModel;
|
||||
use App\Helpers\TPADataCompareHelper;
|
||||
use App\Helpers\TPADataCompareHelper2;
|
||||
@ -25,6 +26,7 @@ class ApiServiceController extends BaseController
|
||||
// protected $format = 'json';
|
||||
protected $db;
|
||||
protected $employeePolicyModel;
|
||||
protected $claimFilesModel;
|
||||
protected $medi_assist_primary_key;
|
||||
protected $vidal_primary_key;
|
||||
protected $icici_primary_key;
|
||||
@ -36,6 +38,7 @@ class ApiServiceController extends BaseController
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->employeePolicyModel = new EmployeePolicyModel();
|
||||
$this->claimFilesModel = new ClaimFilesModel();
|
||||
$this->medi_assist_primary_key = getenv('MEDI_ASSIST_PRIMARY_KEY_CONSTANT');
|
||||
$this->vidal_primary_key = getenv('VIDAL_PRIMARY_KEY_CONSTANT');
|
||||
$this->icici_primary_key = getenv('ICICI_PRIMARY_KEY_CONSTANT');
|
||||
@ -177,26 +180,20 @@ class ApiServiceController extends BaseController
|
||||
$voloApiController = new VoloApiController();
|
||||
$data['eCardDownload'] = $voloApiController->EcardRequest( $emp_code, $policy_no , $employee_policy[0]['tpa_id'] );
|
||||
|
||||
}else{
|
||||
|
||||
if($type == "download"){
|
||||
// direct download
|
||||
$data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/1';
|
||||
}else{
|
||||
if(isset($all_member) && !empty($all_member)){
|
||||
// view and download all members
|
||||
$data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/1/1';
|
||||
}else{
|
||||
// view and download single member
|
||||
$data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/0/1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['message'] = "E-card generated";
|
||||
if(empty($data['eCardDownload'])){
|
||||
$data['message'] = "E-card not generated";
|
||||
}
|
||||
if (empty($data['eCardDownload'])) {
|
||||
$data['eCardDownload'] = $this->buildDefaultEcardDownloadUrl(
|
||||
$employee_policy[0]['rand_string'],
|
||||
$type,
|
||||
$all_member ?? null
|
||||
);
|
||||
}
|
||||
|
||||
$data['message'] = "E-card generated";
|
||||
if(empty($data['eCardDownload'])){
|
||||
$data['message'] = "E-card not generated";
|
||||
}
|
||||
|
||||
} else {
|
||||
$data['eCardDownload'] = null;
|
||||
@ -220,6 +217,19 @@ class ApiServiceController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
private function buildDefaultEcardDownloadUrl(string $randString, string $type = 'download', $allMember = null): string
|
||||
{
|
||||
if ($type === 'download') {
|
||||
return base_url('download-e-card/') . $randString . '/1';
|
||||
}
|
||||
|
||||
if (!empty($allMember)) {
|
||||
return base_url('download-e-card/') . $randString . '/1/1';
|
||||
}
|
||||
|
||||
return base_url('download-e-card/') . $randString . '/0/1';
|
||||
}
|
||||
|
||||
// Get TPAID
|
||||
public function getTPAID()
|
||||
{
|
||||
@ -583,6 +593,13 @@ class ApiServiceController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $this->claimFilesModel->hasPdfFileForTicket($claimId)) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'No PDF file found for this claim'
|
||||
]);
|
||||
}
|
||||
|
||||
$result = $this->pushClaims($claimId);
|
||||
|
||||
if ($result !== null && is_array($result)) {
|
||||
|
||||
@ -1297,6 +1297,7 @@ class TicketServiceController extends AdminController
|
||||
} else {
|
||||
|
||||
//check the employee and insured
|
||||
$params['is_from'] = 'claim_dump';
|
||||
$employee_data = $ticketMasterModal->getEmployeeAndEmployeePolicyDetails($params) ?? [];
|
||||
// dd($employee_data);
|
||||
if (count($employee_data) == 0) {
|
||||
|
||||
@ -59,4 +59,18 @@ class ClaimFilesModel extends Model
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the claim (ticket) has at least one active PDF in claim_files.
|
||||
*/
|
||||
public function hasPdfFileForTicket($ticketId): bool
|
||||
{
|
||||
return $this->where('ticket_id', $ticketId)
|
||||
->where('is_active', 1)
|
||||
->groupStart()
|
||||
->where('mime_type', 'pdf')
|
||||
->orWhere('mime_type', 'application/pdf')
|
||||
->groupEnd()
|
||||
->countAllResults(false) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1118,12 +1118,23 @@ class TicketMasterModel extends Model
|
||||
$policy_no = $params['policy_no'] ?? null;
|
||||
$relationship = $params['relationship'] ?? null;
|
||||
$insured_name = $params['insured_name'] ?? null;
|
||||
$is_from = $params['is_from'] ?? null;
|
||||
|
||||
// $client_name = "6-Eleven";
|
||||
// $emp_code = "EMP0020K12";
|
||||
// $emp_name = "Lokesh";
|
||||
// $policy_no = "GMC-1999/2000/2021/2022";
|
||||
|
||||
$base_policy_id = null;
|
||||
if($is_from == "claim_dump"){
|
||||
$client_policy_data = $this->db->table('client_policy')->where('policy_no', trim($policy_no))->where('is_active', 1)->get()->getRowArray();
|
||||
if(isset($client_policy_data) && !empty($client_policy_data)){
|
||||
if(!empty($client_policy_data['base_policy'])) {
|
||||
$base_policy_id = $client_policy_data['base_policy'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$builder = $this->db->table('employees e');
|
||||
$builder->select("
|
||||
e.id as emp_id,
|
||||
@ -1161,7 +1172,13 @@ class TicketMasterModel extends Model
|
||||
$builder->where('e.emp_code', trim($emp_code));
|
||||
$builder->where('e.name', trim($emp_name));
|
||||
$builder->where('c.client_name', trim($client_name));
|
||||
$builder->where('cp.policy_no', trim($policy_no));
|
||||
|
||||
if(!empty($base_policy_id)) {
|
||||
$builder->where('cp.id', trim($base_policy_id));
|
||||
} else {
|
||||
$builder->where('cp.policy_no', trim($policy_no));
|
||||
}
|
||||
|
||||
$builder->where('LOWER(e.relationship)', strtolower('self'));
|
||||
|
||||
$query = $builder->get();
|
||||
|
||||
@ -163,7 +163,8 @@
|
||||
</h4> -->
|
||||
</div>
|
||||
<form role="form" class="parsley-examples" method="post" id="leads_form_id"
|
||||
enctype="multipart/form-data">
|
||||
enctype="multipart/form-data"
|
||||
data-parsley-excluded="input[type=button], input[type=submit], input[type=reset], input[type=hidden], [disabled], :hidden, .select2-search__field">
|
||||
|
||||
<input type="hidden" name="id" id="leads_primarykey">
|
||||
<input type="hidden" name="lead_form_type" id="lead_form_type_id" value="<?= isset($selected_lead_type) ? $selected_lead_type : 1 ?>">
|
||||
@ -487,7 +488,7 @@
|
||||
|
||||
function restoreActualLeadGstNumber() {
|
||||
if ($('#actual_lead_id').val() && $('#actual_lead_id').val() != 0 && actualLeadGstNumber) {
|
||||
$('#gst').val(actualLeadGstNumber);
|
||||
$('#gst').val(String(actualLeadGstNumber).trim().toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1774,15 +1775,51 @@
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (typeof window.prepareLeadsFormForSubmit === 'function') {
|
||||
window.prepareLeadsFormForSubmit();
|
||||
}
|
||||
|
||||
var isValid = $('#leads_form_id').parsley().validate();
|
||||
|
||||
if (!isValid) {
|
||||
$('#leads_form_id').find('input, select, textarea').each(function() {
|
||||
if ($(this).parsley().isValid() === false && !$(this).val()) {
|
||||
console.log('Empty field ID:', this.id);
|
||||
var invalidFields = typeof window.getLeadsFormInvalidFields === 'function'
|
||||
? window.getLeadsFormInvalidFields()
|
||||
: [];
|
||||
|
||||
if (invalidFields.length) {
|
||||
console.table(invalidFields);
|
||||
invalidFields.forEach(function(f) {
|
||||
console.log('Invalid field:', f.label || f.name || f.id, f);
|
||||
});
|
||||
|
||||
var firstInvalid = invalidFields[0];
|
||||
var fieldLabel = firstInvalid.label || firstInvalid.name || firstInvalid.id || 'A required field';
|
||||
var fieldMessage = (firstInvalid.messages && firstInvalid.messages.length)
|
||||
? firstInvalid.messages[0]
|
||||
: (firstInvalid.isEmpty ? 'This field is required.' : 'Please check this field.');
|
||||
|
||||
if (typeof toastr !== 'undefined') {
|
||||
toastr.warning(fieldLabel + ': ' + fieldMessage, 'Validation');
|
||||
}
|
||||
});
|
||||
console.log('Form is Empty', 'Warning');
|
||||
|
||||
if (firstInvalid.id) {
|
||||
var $invalidField = $('#' + firstInvalid.id);
|
||||
if ($invalidField.length) {
|
||||
var scrollTarget = $invalidField.closest('.form-group, .card, .dynamic-form-row');
|
||||
if (scrollTarget.length) {
|
||||
$('html, body').animate({
|
||||
scrollTop: scrollTarget.offset().top - 100
|
||||
}, 300);
|
||||
}
|
||||
$invalidField.focus();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.warn('Form validation failed');
|
||||
if (typeof toastr !== 'undefined') {
|
||||
toastr.warning('Please correct the highlighted fields.', 'Validation');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2564,6 +2601,10 @@
|
||||
toggleRequiredFields();
|
||||
restoreActualLeadGstNumber();
|
||||
restoreActualLeadContactDetails();
|
||||
|
||||
if (typeof window.refreshLeadsFormValidation === 'function') {
|
||||
window.refreshLeadsFormValidation();
|
||||
}
|
||||
}
|
||||
|
||||
function toggleRequiredFields() {
|
||||
@ -2694,7 +2735,7 @@
|
||||
actualLeadClientName = actual_lead_client_details.company_name || '';
|
||||
$('#client_name').val(actualLeadClientName);
|
||||
|
||||
actualLeadGstNumber = actual_lead_client_details.gst_number || actual_lead_client_details.gst || '';
|
||||
actualLeadGstNumber = (actual_lead_client_details.gst_number || actual_lead_client_details.gst || '').toString().trim().toUpperCase();
|
||||
$('#gst').val(actualLeadGstNumber);
|
||||
if (actual_lead_client_details.client_type !== undefined && actual_lead_client_details.client_type !== null && actual_lead_client_details.client_type !== '') {
|
||||
$('#client_type').val(String(actual_lead_client_details.client_type));
|
||||
|
||||
@ -39,12 +39,25 @@
|
||||
<div class="card" style="margin-right: 23px;">
|
||||
<div class="card-body">
|
||||
|
||||
<?php
|
||||
$tpaActionButtons = '';
|
||||
if (
|
||||
!empty($ticket_data['is_tpa_api_service_enabled']) &&
|
||||
empty($ticket_data['tpa_claim_push_reference_no']) &&
|
||||
($ticket_data['claim_created_by'] ?? '') !== 'TPA'
|
||||
) {
|
||||
$tpaActionButtons .= ' <a href="#" class="btn btn-success btn-sm mr-2" onclick="manualTpaClaimPush(); return false;">Manual TPA Claim Push</a>';
|
||||
}
|
||||
if (!empty($ticket_data['tpa_claim_push_reference_no'])) {
|
||||
$tpaActionButtons .= ' <a href="#" class="btn btn-success btn-sm mr-2" onclick="fetchTpaClaimStatus(); return false;">Fetch Claim Status</a>';
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
var pageHideMainNavTitle = true;
|
||||
var pageTitle = 'Claims<?php if(isset($ticket_data["tpa_claim_push_reference_no"]) && !empty($ticket_data["tpa_claim_push_reference_no"])) { echo " <a href=\"#\" class=\"btn btn-success mr-2\" onclick=\"fetchTpaClaimStatus()\">Fetch Claim Status</a>"; } ?>';
|
||||
var pageTitle = 'Claims <?= $tpaActionButtons ?>';
|
||||
var pageBackButton = '<a href="<?= base_url("ticket/list"); ?>" class="topbar-icon-btn" data-toggle="tooltip" data-placement="top" title="Back" aria-label="Back to list"><i class="ri-arrow-left-s-line"></i></a>';
|
||||
</script>
|
||||
<!-- Header Section -->
|
||||
<!-- Header Section (TPA actions rendered in top navbar via pageTitle) -->
|
||||
<!-- <div class="row mb-3 align-items-center justify-content-between">
|
||||
<div class="col-auto">
|
||||
<h4 class="mb-0">Claims</h4>
|
||||
@ -56,7 +69,7 @@
|
||||
<?php if (
|
||||
$ticket_data['is_tpa_api_service_enabled'] == true &&
|
||||
empty($ticket_data['tpa_claim_push_reference_no']) &&
|
||||
empty($ticket_data['claim_number'])
|
||||
$ticket_data['claim_created_by'] != 'TPA'
|
||||
) : ?>
|
||||
<a href="#" class="btn btn-success mr-2" onclick="manualTpaClaimPush(); return false;">
|
||||
Manual TPA Claim Push
|
||||
|
||||
@ -577,6 +577,104 @@
|
||||
<script>
|
||||
let GlobelExtraFields = [];
|
||||
var doa;
|
||||
var STATUS_SECTION_CLASSES = ['cda_ir', 'settled', 'approved', 'rejected', 'up_qdr', 'up_cnu', 'canceled', 'returned', 'payment', 'non_id'];
|
||||
var statusSectionInitialValues = {};
|
||||
|
||||
function captureSectionInitialValues(sectionClass) {
|
||||
if (!sectionClass) {
|
||||
return;
|
||||
}
|
||||
var values = {};
|
||||
$('.' + sectionClass).find('input, textarea, select').each(function() {
|
||||
var el = this;
|
||||
var key = el.id || el.name;
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
values[key] = el.type === 'file' ? '' : String($(el).val() || '');
|
||||
});
|
||||
statusSectionInitialValues[sectionClass] = values;
|
||||
}
|
||||
|
||||
function captureAllStatusSectionInitialValues() {
|
||||
STATUS_SECTION_CLASSES.forEach(captureSectionInitialValues);
|
||||
}
|
||||
|
||||
function hasSectionChanged(sectionClass) {
|
||||
if (!sectionClass) {
|
||||
return false;
|
||||
}
|
||||
var initial = statusSectionInitialValues[sectionClass];
|
||||
if (!initial) {
|
||||
return false;
|
||||
}
|
||||
var changed = false;
|
||||
$('.' + sectionClass).find('input, textarea, select').each(function() {
|
||||
var el = this;
|
||||
var key = el.id || el.name;
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
if (el.type === 'file') {
|
||||
if (el.files && el.files.length > 0) {
|
||||
changed = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
var current = String($(el).val() || '');
|
||||
var original = String(initial[key] !== undefined ? initial[key] : '');
|
||||
if (current !== original) {
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
return changed;
|
||||
}
|
||||
|
||||
function updateSectionRequiredLabels(sectionClass, isRequired) {
|
||||
if (!sectionClass) {
|
||||
return;
|
||||
}
|
||||
$('.' + sectionClass).find('input, textarea, select').each(function() {
|
||||
var fieldId = $(this).attr('id');
|
||||
if (!fieldId || fieldId === 'approved_description') {
|
||||
return;
|
||||
}
|
||||
var $label = $("label[for='" + fieldId + "']");
|
||||
if (!$label.length) {
|
||||
return;
|
||||
}
|
||||
if (isRequired && !$label.find('.text-danger').length) {
|
||||
$label.append(' <span class="text-danger">*</span>');
|
||||
} else if (!isRequired) {
|
||||
$label.find('.text-danger').remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function applyConditionalRequiredForSection(sectionClass) {
|
||||
if (!sectionClass) {
|
||||
return;
|
||||
}
|
||||
if (sectionClass === 'approved' || sectionClass === 'settled') {
|
||||
enforceLetterPairRules();
|
||||
updateSectionRequiredLabels(sectionClass, hasSectionChanged(sectionClass));
|
||||
return;
|
||||
}
|
||||
var changed = hasSectionChanged(sectionClass);
|
||||
$('.' + sectionClass).find('input, textarea, select').each(function() {
|
||||
if (this.id === 'approved_description') {
|
||||
return;
|
||||
}
|
||||
$(this).prop('required', changed);
|
||||
});
|
||||
updateSectionRequiredLabels(sectionClass, changed);
|
||||
}
|
||||
|
||||
function refreshAllStatusSectionRequired() {
|
||||
STATUS_SECTION_CLASSES.forEach(applyConditionalRequiredForSection);
|
||||
$('#approved_description').prop('required', false);
|
||||
$("label[for='approved_description'] .text-danger").remove();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
@ -645,6 +743,8 @@
|
||||
GlobelExtraFields = extraFields;
|
||||
console.log("extraFields", extraFields);
|
||||
claimStatusFieldChanges(extraFields);
|
||||
captureAllStatusSectionInitialValues();
|
||||
refreshAllStatusSectionRequired();
|
||||
handleTPARequired(tpa_id_for_hid_filed);
|
||||
// syncApprovedLetterInputs();
|
||||
// syncSettleLetterInputs();
|
||||
@ -736,24 +836,16 @@
|
||||
showClass = '.payment';
|
||||
}
|
||||
|
||||
// Show the relevant section and enable required attributes
|
||||
if (showClass) {
|
||||
// $(showClass).show().find('input, textarea').attr('required', true);
|
||||
$(showClass).show().find('input, textarea').attr('required', true).each(function() {
|
||||
var $label = $("label[for='" + $(this).attr('id') + "']");
|
||||
if ($label.length && !$label.find('.text-danger').length) {
|
||||
$label.append(' <span class="text-danger">*</span>');
|
||||
}
|
||||
});
|
||||
|
||||
$(showClass).show();
|
||||
captureSectionInitialValues(showClass.replace('.', ''));
|
||||
}
|
||||
|
||||
$field = $('#approved_description')
|
||||
$field.prop('required', false);
|
||||
var $parentDiv = $field.closest("div");
|
||||
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
|
||||
syncApprovedLetterInputs();
|
||||
syncSettleLetterInputs();
|
||||
refreshAllStatusSectionRequired();
|
||||
}
|
||||
|
||||
$('#claim_status_id').on('change', function() {
|
||||
@ -837,13 +929,13 @@
|
||||
const hasUrl = $.trim($urlInput.val()) !== '';
|
||||
const hasFile = $fileInput[0].files && $fileInput[0].files.length > 0;
|
||||
const isApprovedSectionVisible = $urlInput.closest('.approved').is(':visible');
|
||||
const approvedSectionChanged = hasSectionChanged('approved');
|
||||
|
||||
$fileInput.prop('disabled', hasUrl);
|
||||
$urlInput.prop('disabled', hasFile);
|
||||
|
||||
// Keep the file optional; URL remains conditionally required for approved state unless file is present.
|
||||
$fileInput.prop('required', false);
|
||||
$urlInput.prop('required', isApprovedSectionVisible && !hasFile);
|
||||
$urlInput.prop('required', isApprovedSectionVisible && approvedSectionChanged && !hasFile);
|
||||
}
|
||||
|
||||
function syncSettleLetterInputs() {
|
||||
@ -857,12 +949,13 @@
|
||||
const hasUrl = $.trim($urlInput.val()) !== '';
|
||||
const hasFile = $fileInput[0].files && $fileInput[0].files.length > 0;
|
||||
const isSettledSectionVisible = $urlInput.closest('.settled').is(':visible');
|
||||
const settledSectionChanged = hasSectionChanged('settled');
|
||||
|
||||
$fileInput.prop('disabled', hasUrl);
|
||||
$urlInput.prop('disabled', hasFile);
|
||||
|
||||
$fileInput.prop('required', false);
|
||||
$urlInput.prop('required', isSettledSectionVisible && !hasFile);
|
||||
$urlInput.prop('required', isSettledSectionVisible && settledSectionChanged && !hasFile);
|
||||
}
|
||||
|
||||
function enforceLetterPairRules() {
|
||||
@ -956,10 +1049,14 @@
|
||||
}
|
||||
|
||||
var selectedClaimStatus = $('#claim_status_id').val();
|
||||
|
||||
if (thirdClass === 'approved' || thirdClass === 'settled') {
|
||||
applyConditionalRequiredForSection(thirdClass);
|
||||
return;
|
||||
}
|
||||
|
||||
var sectionChanged = hasSectionChanged(thirdClass);
|
||||
var $thirdClass = $(`.${thirdClass}`);
|
||||
var hasValue = $thirdClass.find('input, textarea, select').filter(function() {
|
||||
return $(this).val().trim() !== ''; // Check if at least one field is not empty
|
||||
}).length > 0;
|
||||
|
||||
$thirdClass.each(function() {
|
||||
var id = $(this).find('[id]').first().attr('id');
|
||||
@ -967,27 +1064,19 @@
|
||||
var $thisDiv = $(this);
|
||||
var $inputs = $thisDiv.find('input, textarea, select');
|
||||
|
||||
|
||||
// ✅ Condition 1: Check if this ID is in extraFieldsArray (required by status)
|
||||
var shouldAddRequired = extrafieldsArray[selectedClaimStatus] && extrafieldsArray[selectedClaimStatus].includes(id);
|
||||
|
||||
// ✅ Condition 2: If any field in the class has a value, make all required
|
||||
if (shouldAddRequired || hasValue) {
|
||||
if (shouldAddRequired || sectionChanged) {
|
||||
if ($label.length && !$label.find('.text-danger').length) {
|
||||
$label.append(' <span class="text-danger">*</span>');
|
||||
}
|
||||
console.log("input from if ", $inputs);
|
||||
// $inputs.attr('required', true);
|
||||
$('.' + thirdClass).find('input, textarea,select').attr('required', true);
|
||||
} else {
|
||||
$label.find('.text-danger').remove();
|
||||
console.log("input ", $inputs);
|
||||
// $inputs.prop('required', false);
|
||||
$('.' + thirdClass).find('input, textarea,select').attr('required', false);
|
||||
}
|
||||
});
|
||||
|
||||
// Re-apply URL/file pair rules after bulk required toggles.
|
||||
enforceLetterPairRules();
|
||||
|
||||
}
|
||||
@ -1034,12 +1123,12 @@
|
||||
$field.prop('required', false);
|
||||
var $parentDiv = $field.closest("div");
|
||||
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
|
||||
enforceLetterPairRules();
|
||||
refreshAllStatusSectionRequired();
|
||||
|
||||
});
|
||||
|
||||
$('#ticket_form_data').on('submit', function() {
|
||||
enforceLetterPairRules();
|
||||
refreshAllStatusSectionRequired();
|
||||
});
|
||||
|
||||
// function addRequiredFieldSymbol(field_name) {
|
||||
|
||||
@ -29,7 +29,44 @@
|
||||
}
|
||||
|
||||
function isSkippableField(el) {
|
||||
return !el || el.disabled || el.type === 'hidden';
|
||||
if (!el || el.disabled || el.type === 'hidden') {
|
||||
return true;
|
||||
}
|
||||
if (el.classList && el.classList.contains('select2-search__field')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isVisibleForValidation(el) {
|
||||
if (isSkippableField(el)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var jq = getJq();
|
||||
if (!jq) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var $el = jq(el);
|
||||
if (!$el.length || !$el.is(':visible')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $el.closest('.form-group, .dynamic-form-row, .claim-row, .col-md-4, .col-md-12').filter(function () {
|
||||
var display = jq(this).css('display');
|
||||
return display === 'none';
|
||||
}).length === 0;
|
||||
}
|
||||
|
||||
function isEmptyValue(val) {
|
||||
if (val == null || val === '') {
|
||||
return true;
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
return val.length === 0;
|
||||
}
|
||||
return String(val).trim() === '';
|
||||
}
|
||||
|
||||
function isPanOrGstField(el) {
|
||||
@ -95,7 +132,7 @@
|
||||
return true;
|
||||
}
|
||||
if (instance.$element.prop('required') && v.length === 0) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return v.length === 10;
|
||||
},
|
||||
@ -181,7 +218,7 @@
|
||||
}
|
||||
|
||||
function validateField(field) {
|
||||
if (!field || isSkippableField(field) || !isParsleyReady()) {
|
||||
if (!field || !isVisibleForValidation(field) || !isParsleyReady()) {
|
||||
return;
|
||||
}
|
||||
var $field = $(field);
|
||||
@ -200,6 +237,70 @@
|
||||
}
|
||||
}
|
||||
|
||||
function prepareHiddenFieldsForSubmit($form) {
|
||||
if (!$form || !$form.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form.find('input, textarea, select').each(function () {
|
||||
var el = this;
|
||||
var $el = $(el);
|
||||
|
||||
if (isVisibleForValidation(el)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$el.removeAttr('required').prop('required', false);
|
||||
clearAttrs($el);
|
||||
|
||||
try {
|
||||
if (typeof $el.parsley === 'function') {
|
||||
var fieldInstance = $el.parsley();
|
||||
if (fieldInstance && typeof fieldInstance.reset === 'function') {
|
||||
fieldInstance.reset();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// no-op
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getInvalidFields($form) {
|
||||
var invalid = [];
|
||||
|
||||
if (!$form || !$form.length || !isParsleyReady()) {
|
||||
return invalid;
|
||||
}
|
||||
|
||||
var instance = $form.parsley();
|
||||
if (!instance) {
|
||||
return invalid;
|
||||
}
|
||||
|
||||
instance.fields.forEach(function (field) {
|
||||
if (field.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var el = field.$element[0];
|
||||
if (!isVisibleForValidation(el)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var val = field.$element.val();
|
||||
invalid.push({
|
||||
id: field.$element.attr('id') || '',
|
||||
name: field.$element.attr('name') || '',
|
||||
label: (field.$element.closest('.form-group, .mb-3, .col-md-4, .col-lg-4').find('label').first().text() || '').trim(),
|
||||
messages: field.getErrorsMessages ? field.getErrorsMessages() : [],
|
||||
isEmpty: isEmptyValue(val)
|
||||
});
|
||||
});
|
||||
|
||||
return invalid;
|
||||
}
|
||||
|
||||
function init() {
|
||||
var $form = $(FORM_SELECTOR);
|
||||
if (!$form.length || !isParsleyReady()) {
|
||||
@ -207,6 +308,7 @@
|
||||
}
|
||||
|
||||
registerValidators();
|
||||
prepareHiddenFieldsForSubmit($form);
|
||||
applyConstraints($form);
|
||||
refreshParsley($form);
|
||||
|
||||
@ -226,6 +328,22 @@
|
||||
window.refreshLeadsFormValidation = function () {
|
||||
init();
|
||||
};
|
||||
|
||||
window.prepareLeadsFormForSubmit = function () {
|
||||
var $form = $(FORM_SELECTOR);
|
||||
if (!$form.length || !isParsleyReady()) {
|
||||
return;
|
||||
}
|
||||
|
||||
registerValidators();
|
||||
prepareHiddenFieldsForSubmit($form);
|
||||
applyConstraints($form);
|
||||
refreshParsley($form);
|
||||
};
|
||||
|
||||
window.getLeadsFormInvalidFields = function () {
|
||||
return getInvalidFields($(FORM_SELECTOR));
|
||||
};
|
||||
})(function () {
|
||||
return window.jQuery;
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user