diff --git a/app/Views/ticket_form_gpa.php b/app/Views/ticket_form_gpa.php
index 29fa66ae..48665d88 100644
--- a/app/Views/ticket_form_gpa.php
+++ b/app/Views/ticket_form_gpa.php
@@ -281,12 +281,23 @@
value="= isset($ticket_data['approved_date']) ? $ticket_data['approved_date'] : '' ?>" name="approved_date">
-
-
-
+
+
+
+
+
+ Only PDF allowed.
+
+
-
-
-
+
+
+
+
+
+ Only PDF allowed.
+
+
@@ -432,6 +454,8 @@
GlobelExtraFields = extraFields;
console.log("extraFields", extraFields);
claimStatusFieldChanges(extraFields);
+ // syncApprovedLetterInputs();
+ // syncSettleLetterInputs();
})
@@ -458,6 +482,7 @@
$field.prop('required', false);
var $parentDiv = $field.closest("div");
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
+ enforceLetterPairRules();
}
@@ -465,6 +490,72 @@
updateClaimStatusDisplay($(this).val());
});
+ function validateApprovedLetterPdf(fileInput) {
+ const file = fileInput.files && fileInput.files[0] ? fileInput.files[0] : null;
+ if (!file) {
+ return true;
+ }
+
+ const fileName = (file.name || '').toLowerCase();
+ const isPdfByName = fileName.endsWith('.pdf');
+ const mimeType = (file.type || '').toLowerCase();
+ const isPdfByType = mimeType === '' || mimeType === 'application/pdf' || mimeType === 'application/x-pdf';
+ const fieldLabel = fileInput.id === 'settle_letter_file' ? 'Settle Letter' : 'Approved Letter';
+
+ if (!isPdfByName || !isPdfByType) {
+ fileInput.value = '';
+ toastr.warning('Only PDF files are allowed for ' + fieldLabel + '.', 'Warning');
+ return false;
+ }
+
+ return true;
+ }
+
+ function syncApprovedLetterInputs() {
+ const $urlInput = $('#approved_letter');
+ const $fileInput = $('#approved_letter_file');
+
+ if (!$urlInput.length || !$fileInput.length) {
+ return;
+ }
+
+ const hasUrl = $.trim($urlInput.val()) !== '';
+ const hasFile = $fileInput[0].files && $fileInput[0].files.length > 0;
+ const isApprovedSectionVisible = $urlInput.closest('.approved').is(':visible');
+
+ $fileInput.prop('disabled', hasUrl);
+ $urlInput.prop('disabled', hasFile);
+
+ $fileInput.prop('required', false);
+ $urlInput.prop('required', isApprovedSectionVisible && !hasFile);
+ }
+
+ function syncSettleLetterInputs() {
+ const $urlInput = $('#settle_letter');
+ const $fileInput = $('#settle_letter_file');
+
+ if (!$urlInput.length || !$fileInput.length) {
+ return;
+ }
+
+ const hasUrl = $.trim($urlInput.val()) !== '';
+ const hasFile = $fileInput[0].files && $fileInput[0].files.length > 0;
+
+ $fileInput.prop('disabled', hasUrl);
+ $urlInput.prop('disabled', hasFile);
+
+ // Settled Letter should remain optional by default.
+ $fileInput.prop('required', false);
+ $urlInput.prop('required', false);
+ $("label[for='settle_letter'] .text-danger").remove();
+ $("label[for='settle_letter_file'] .text-danger").remove();
+ }
+
+ function enforceLetterPairRules() {
+ syncApprovedLetterInputs();
+ syncSettleLetterInputs();
+ }
+
function claimStatusFieldChanges(fields) {
console.log('fields', fields);
fields.forEach(function(fieldId) {
@@ -480,6 +571,13 @@
if ($label.length && !$label.find(".text-danger").length) {
// $label.append(' *');
}
+
+ // Keep paired PDF upload visibility in sync with URL field visibility.
+ if (fieldId === 'approved_letter') {
+ $('#approved_letter_file').closest('div').show();
+ } else if (fieldId === 'settle_letter') {
+ $('#settle_letter_file').closest('div').show();
+ }
}
});
}
@@ -554,6 +652,9 @@
}
});
+ // Re-apply URL/file pair rules after bulk required toggles.
+ enforceLetterPairRules();
+
}
@@ -565,7 +666,7 @@
console.log('targetId', targetId);
console.log('fields.includes(targetId)', fields.includes(targetId));
- if (fields.includes(targetId)) {
+ if (fields.includes(targetId) || targetId == "approved_letter_file" || targetId == "settle_letter_file") {
let $field = $("#" + targetId);
console.log('$field id', $field);
@@ -593,8 +694,31 @@
$field.prop('required', false);
var $parentDiv = $field.closest("div");
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
+ enforceLetterPairRules();
});
+
+ $('#approved_letter').on('input blur', function () {
+ enforceLetterPairRules();
+ });
+
+ $('#approved_letter_file').on('change', function () {
+ validateApprovedLetterPdf(this);
+ enforceLetterPairRules();
+ });
+
+ $('#settle_letter').on('input blur', function () {
+ enforceLetterPairRules();
+ });
+
+ $('#settle_letter_file').on('change', function () {
+ validateApprovedLetterPdf(this);
+ enforceLetterPairRules();
+ });
+
+ $('#ticket_form_data').on('submit', function() {
+ enforceLetterPairRules();
+ });
// function addRequiredFieldSymbol(field_name) {
// // Find the field with the given name
// var $field = $(`[name="${field_name}"]`);