FEAT_ENABLE_PDF_UPLOAD_OPTION_FOR_APPREOVE_AND_SETTLED_LETTER
This commit is contained in:
parent
ad6ab53a6f
commit
badd42b565
@ -695,6 +695,7 @@ class MediAssistApiController extends BaseController
|
|||||||
$fileData = $this->db->table('claim_files f')
|
$fileData = $this->db->table('claim_files f')
|
||||||
->where('f.ticket_id', $claimId)
|
->where('f.ticket_id', $claimId)
|
||||||
->where('f.docs_for_ir', 1)
|
->where('f.docs_for_ir', 1)
|
||||||
|
->where('f.file_type', 2) // PDF
|
||||||
->get()
|
->get()
|
||||||
->getResultArray();
|
->getResultArray();
|
||||||
|
|
||||||
|
|||||||
@ -1140,6 +1140,8 @@ class TicketController extends BaseController
|
|||||||
public function createTicket()
|
public function createTicket()
|
||||||
{
|
{
|
||||||
$request_data = $this->request->getPost();
|
$request_data = $this->request->getPost();
|
||||||
|
$approvedLetterFile = $this->request->getFile('approved_letter_file');
|
||||||
|
$settleLetterFile = $this->request->getFile('settle_letter_file');
|
||||||
$selected_ticket_type = $this->request->getPost('ticket_type_id');
|
$selected_ticket_type = $this->request->getPost('ticket_type_id');
|
||||||
|
|
||||||
// 1. Initialize an empty rules array
|
// 1. Initialize an empty rules array
|
||||||
@ -1455,6 +1457,84 @@ class TicketController extends BaseController
|
|||||||
$request_data = $this->request->getPost();
|
$request_data = $this->request->getPost();
|
||||||
$sanitized_data = sanitizeInputArrayAdvanced($request_data);
|
$sanitized_data = sanitizeInputArrayAdvanced($request_data);
|
||||||
$ticket_data = $this->formatDateForClaim($sanitized_data);
|
$ticket_data = $this->formatDateForClaim($sanitized_data);
|
||||||
|
$approvedLetterUrl = trim((string) ($ticket_data['approved_letter'] ?? ''));
|
||||||
|
$settleLetterUrl = trim((string) ($ticket_data['settle_letter'] ?? ''));
|
||||||
|
$hasApprovedLetterFile = $approvedLetterFile !== null
|
||||||
|
&& $approvedLetterFile->isValid()
|
||||||
|
&& $approvedLetterFile->getError() !== UPLOAD_ERR_NO_FILE;
|
||||||
|
$hasSettleLetterFile = $settleLetterFile !== null
|
||||||
|
&& $settleLetterFile->isValid()
|
||||||
|
&& $settleLetterFile->getError() !== UPLOAD_ERR_NO_FILE;
|
||||||
|
|
||||||
|
if ($approvedLetterUrl !== '' && $hasApprovedLetterFile) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['approved_letter' => 'Provide either Approved Letter URL or Approved Letter PDF file, not both.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($approvedLetterUrl !== '' && ! $this->isClaimUploadUrl($approvedLetterUrl)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['approved_letter' => 'Approved Letter URL format is invalid.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($settleLetterUrl !== '' && $hasSettleLetterFile) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['settle_letter' => 'Provide either Settle Letter URL or Settle Letter PDF file, not both.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($settleLetterUrl !== '' && ! $this->isClaimUploadUrl($settleLetterUrl)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['settle_letter' => 'Settle Letter URL format is invalid.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadedApprovedLetter = null;
|
||||||
|
if ($hasApprovedLetterFile) {
|
||||||
|
$uploadResult = $this->uploadApprovedLetterPdf($approvedLetterFile, 'Approved Letter');
|
||||||
|
if (! ($uploadResult['status'] ?? false)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['approved_letter_file' => $uploadResult['message'] ?? 'Invalid Approved Letter file.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$uploadedApprovedLetter = $uploadResult['data'];
|
||||||
|
$ticket_data['approved_letter'] = '';
|
||||||
|
} else {
|
||||||
|
$ticket_data['approved_letter'] = $approvedLetterUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadedSettleLetter = null;
|
||||||
|
if ($hasSettleLetterFile) {
|
||||||
|
$uploadResult = $this->uploadApprovedLetterPdf($settleLetterFile, 'Settle Letter');
|
||||||
|
if (! ($uploadResult['status'] ?? false)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['settle_letter_file' => $uploadResult['message'] ?? 'Invalid Settle Letter file.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$uploadedSettleLetter = $uploadResult['data'];
|
||||||
|
$ticket_data['settle_letter'] = '';
|
||||||
|
} else {
|
||||||
|
$ticket_data['settle_letter'] = $settleLetterUrl;
|
||||||
|
}
|
||||||
// $ticket_data = $this->getLastMatchedStatus($ticket_data, );
|
// $ticket_data = $this->getLastMatchedStatus($ticket_data, );
|
||||||
// print_rr($ticket_data); die;
|
// print_rr($ticket_data); die;
|
||||||
|
|
||||||
@ -1499,6 +1579,37 @@ class TicketController extends BaseController
|
|||||||
$ticket_data['claim_created_by'] = "CRM";
|
$ticket_data['claim_created_by'] = "CRM";
|
||||||
$return_value = $this->ticketMasterModel->insert($ticket_data);
|
$return_value = $this->ticketMasterModel->insert($ticket_data);
|
||||||
if ($return_value) {
|
if ($return_value) {
|
||||||
|
if ($uploadedApprovedLetter !== null) {
|
||||||
|
$approvedLetterDownloadUrl = $this->createApprovedLetterFileUrl(
|
||||||
|
(int) $return_value,
|
||||||
|
(int) ($ticket_data['ticket_type_id'] ?? 1),
|
||||||
|
$uploadedApprovedLetter,
|
||||||
|
'APPROVED_LETTER_PDF'
|
||||||
|
);
|
||||||
|
$ticket_data['approved_letter'] = $approvedLetterDownloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($uploadedSettleLetter !== null) {
|
||||||
|
$settleLetterDownloadUrl = $this->createApprovedLetterFileUrl(
|
||||||
|
(int) $return_value,
|
||||||
|
(int) ($ticket_data['ticket_type_id'] ?? 1),
|
||||||
|
$uploadedSettleLetter,
|
||||||
|
'SETTLE_LETTER_PDF'
|
||||||
|
);
|
||||||
|
$ticket_data['settle_letter'] = $settleLetterDownloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($uploadedApprovedLetter !== null || $uploadedSettleLetter !== null) {
|
||||||
|
$updateUploadedLetterData = [];
|
||||||
|
if (isset($ticket_data['approved_letter'])) {
|
||||||
|
$updateUploadedLetterData['approved_letter'] = $ticket_data['approved_letter'];
|
||||||
|
}
|
||||||
|
if (isset($ticket_data['settle_letter'])) {
|
||||||
|
$updateUploadedLetterData['settle_letter'] = $ticket_data['settle_letter'];
|
||||||
|
}
|
||||||
|
$this->ticketMasterModel->where('id', $return_value)->set($updateUploadedLetterData)->update();
|
||||||
|
}
|
||||||
|
|
||||||
//mail trigger part
|
//mail trigger part
|
||||||
$this->putHistoryAfterInsert($ticket_data, $return_value);
|
$this->putHistoryAfterInsert($ticket_data, $return_value);
|
||||||
$mail_responce = $this->sendAutoMailTrigger($return_value);
|
$mail_responce = $this->sendAutoMailTrigger($return_value);
|
||||||
@ -1517,6 +1628,8 @@ class TicketController extends BaseController
|
|||||||
{
|
{
|
||||||
|
|
||||||
$request_data = $this->request->getPost();
|
$request_data = $this->request->getPost();
|
||||||
|
$approvedLetterFile = $this->request->getFile('approved_letter_file');
|
||||||
|
$settleLetterFile = $this->request->getFile('settle_letter_file');
|
||||||
$selected_ticket_type = $this->request->getPost('ticket_type_id');
|
$selected_ticket_type = $this->request->getPost('ticket_type_id');
|
||||||
|
|
||||||
// 1. Initialize an empty rules array
|
// 1. Initialize an empty rules array
|
||||||
@ -1832,6 +1945,85 @@ class TicketController extends BaseController
|
|||||||
$sanitized_data = sanitizeInputArrayAdvanced($request_data);
|
$sanitized_data = sanitizeInputArrayAdvanced($request_data);
|
||||||
$ticket_data = $this->formatDateForClaim($sanitized_data);
|
$ticket_data = $this->formatDateForClaim($sanitized_data);
|
||||||
$ticket_id = $this->request->getPost('ticket_master_id');
|
$ticket_id = $this->request->getPost('ticket_master_id');
|
||||||
|
$approvedLetterUrl = trim((string) ($ticket_data['approved_letter'] ?? ''));
|
||||||
|
$settleLetterUrl = trim((string) ($ticket_data['settle_letter'] ?? ''));
|
||||||
|
$hasApprovedLetterFile = $approvedLetterFile !== null
|
||||||
|
&& $approvedLetterFile->isValid()
|
||||||
|
&& $approvedLetterFile->getError() !== UPLOAD_ERR_NO_FILE;
|
||||||
|
$hasSettleLetterFile = $settleLetterFile !== null
|
||||||
|
&& $settleLetterFile->isValid()
|
||||||
|
&& $settleLetterFile->getError() !== UPLOAD_ERR_NO_FILE;
|
||||||
|
|
||||||
|
if ($approvedLetterUrl !== '' && $hasApprovedLetterFile) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['approved_letter' => 'Provide either Approved Letter URL or Approved Letter PDF file, not both.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($approvedLetterUrl !== '' && ! $this->isClaimUploadUrl($approvedLetterUrl)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['approved_letter' => 'Approved Letter URL format is invalid.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($settleLetterUrl !== '' && $hasSettleLetterFile) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['settle_letter' => 'Provide either Settle Letter URL or Settle Letter PDF file, not both.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($settleLetterUrl !== '' && ! $this->isClaimUploadUrl($settleLetterUrl)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['settle_letter' => 'Settle Letter URL format is invalid.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadedApprovedLetter = null;
|
||||||
|
if ($hasApprovedLetterFile) {
|
||||||
|
$uploadResult = $this->uploadApprovedLetterPdf($approvedLetterFile, 'Approved Letter');
|
||||||
|
if (! ($uploadResult['status'] ?? false)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['approved_letter_file' => $uploadResult['message'] ?? 'Invalid Approved Letter file.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$uploadedApprovedLetter = $uploadResult['data'];
|
||||||
|
$ticket_data['approved_letter'] = '';
|
||||||
|
} else {
|
||||||
|
$ticket_data['approved_letter'] = $approvedLetterUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadedSettleLetter = null;
|
||||||
|
if ($hasSettleLetterFile) {
|
||||||
|
$uploadResult = $this->uploadApprovedLetterPdf($settleLetterFile, 'Settle Letter');
|
||||||
|
if (! ($uploadResult['status'] ?? false)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => ['settle_letter_file' => $uploadResult['message'] ?? 'Invalid Settle Letter file.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$uploadedSettleLetter = $uploadResult['data'];
|
||||||
|
$ticket_data['settle_letter'] = '';
|
||||||
|
} else {
|
||||||
|
$ticket_data['settle_letter'] = $settleLetterUrl;
|
||||||
|
}
|
||||||
|
|
||||||
$old_ticket_data = $this->ticketMasterModel->where('id', $ticket_id)->where('is_active', 1)->first();
|
$old_ticket_data = $this->ticketMasterModel->where('id', $ticket_id)->where('is_active', 1)->first();
|
||||||
$ticket_data['claim_status_id'] = $this->getLastMatchedStatus($ticket_data, $old_ticket_data);
|
$ticket_data['claim_status_id'] = $this->getLastMatchedStatus($ticket_data, $old_ticket_data);
|
||||||
$ticket_data['last_updated_by'] = 'USER';
|
$ticket_data['last_updated_by'] = 'USER';
|
||||||
@ -1842,6 +2034,24 @@ class TicketController extends BaseController
|
|||||||
$this->myLogger->logme('error', "[UPDATE_CLAIM] New Ticket Data: {data}", ['data' => json_encode($ticket_data, JSON_PRETTY_PRINT)]);
|
$this->myLogger->logme('error', "[UPDATE_CLAIM] New Ticket Data: {data}", ['data' => json_encode($ticket_data, JSON_PRETTY_PRINT)]);
|
||||||
|
|
||||||
if ($ticket_data) {
|
if ($ticket_data) {
|
||||||
|
if ($uploadedApprovedLetter !== null) {
|
||||||
|
$ticket_data['approved_letter'] = $this->createApprovedLetterFileUrl(
|
||||||
|
(int) $ticket_id,
|
||||||
|
(int) ($ticket_data['ticket_type_id'] ?? 1),
|
||||||
|
$uploadedApprovedLetter,
|
||||||
|
'APPROVED_LETTER_PDF'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($uploadedSettleLetter !== null) {
|
||||||
|
$ticket_data['settle_letter'] = $this->createApprovedLetterFileUrl(
|
||||||
|
(int) $ticket_id,
|
||||||
|
(int) ($ticket_data['ticket_type_id'] ?? 1),
|
||||||
|
$uploadedSettleLetter,
|
||||||
|
'SETTLE_LETTER_PDF'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$return_value = $this->ticketMasterModel->where('id', $ticket_id)->set($ticket_data)->update();
|
$return_value = $this->ticketMasterModel->where('id', $ticket_id)->set($ticket_data)->update();
|
||||||
if ($return_value) {
|
if ($return_value) {
|
||||||
|
|
||||||
@ -3264,6 +3474,55 @@ class TicketController extends BaseController
|
|||||||
return strpos($host, '.') !== false;
|
return strpos($host, '.') !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function uploadApprovedLetterPdf($file, string $documentLabel = 'Approved Letter'): array
|
||||||
|
{
|
||||||
|
if ($file === null || ! $file->isValid() || $file->getError() === UPLOAD_ERR_NO_FILE) {
|
||||||
|
return ['status' => false, 'message' => $documentLabel . ' file is missing.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$ext = strtolower((string) $file->getClientExtension());
|
||||||
|
$mime = strtolower((string) $file->getMimeType());
|
||||||
|
$allowedMime = ['application/pdf', 'application/x-pdf'];
|
||||||
|
|
||||||
|
if ($ext !== 'pdf' || (! empty($mime) && ! in_array($mime, $allowedMime, true))) {
|
||||||
|
return ['status' => false, 'message' => 'Only PDF files are allowed for ' . $documentLabel . ' upload.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadPath = WRITEPATH . 'uploads/claim_files/';
|
||||||
|
if (! is_dir($uploadPath)) {
|
||||||
|
mkdir($uploadPath, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$diskFileName = file_Upload_for_lead($file, $uploadPath, ['pdf']);
|
||||||
|
if (empty($diskFileName)) {
|
||||||
|
return ['status' => false, 'message' => 'Failed to upload ' . $documentLabel . ' file.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'status' => true,
|
||||||
|
'data' => [
|
||||||
|
'file_name' => $diskFileName,
|
||||||
|
'mime_type' => $mime ?: 'application/pdf',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createApprovedLetterFileUrl(int $ticketId, int $ticketTypeId, array $uploadedFile, string $docName = 'APPROVED_LETTER_PDF'): string
|
||||||
|
{
|
||||||
|
$fileId = $this->claimFilesModel->insert([
|
||||||
|
'ticket_id' => $ticketId,
|
||||||
|
'ticket_type' => $ticketTypeId,
|
||||||
|
'file_type' => 3,
|
||||||
|
'doc_name' => $docName,
|
||||||
|
'file_name' => $uploadedFile['file_name'],
|
||||||
|
'url' => $uploadedFile['file_name'],
|
||||||
|
'mime_type' => $uploadedFile['mime_type'] ?? 'application/pdf',
|
||||||
|
'is_active' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return base_url('downloadClaimFile/' . $fileId);
|
||||||
|
}
|
||||||
|
|
||||||
public function upload_url()
|
public function upload_url()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -3379,6 +3638,7 @@ class TicketController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get the claim file list data against the ticket id
|
||||||
public function getUrlDataByTicketId()
|
public function getUrlDataByTicketId()
|
||||||
{
|
{
|
||||||
$ticket_id = $this->request->getPost('ticket_id');
|
$ticket_id = $this->request->getPost('ticket_id');
|
||||||
@ -3401,6 +3661,7 @@ class TicketController extends BaseController
|
|||||||
END AS url
|
END AS url
|
||||||
")
|
")
|
||||||
->where('ticket_id', $ticket_id)
|
->where('ticket_id', $ticket_id)
|
||||||
|
->where('file_type !=', 3) // Assuming you want to fetch both URL and file uploads
|
||||||
->where('is_active', 1)
|
->where('is_active', 1)
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
|
|||||||
@ -1664,6 +1664,7 @@ class VidalApiController extends BaseController
|
|||||||
$fileData = $this->db->table('claim_files f')
|
$fileData = $this->db->table('claim_files f')
|
||||||
->where('f.ticket_id', $claimId)
|
->where('f.ticket_id', $claimId)
|
||||||
->where('f.docs_for_ir', 1)
|
->where('f.docs_for_ir', 1)
|
||||||
|
->where('f.file_type', 2) // PDF
|
||||||
->get()
|
->get()
|
||||||
->getResultArray();
|
->getResultArray();
|
||||||
|
|
||||||
|
|||||||
@ -429,10 +429,26 @@
|
|||||||
value="<?= isset($ticket_data['approved_date']) ? $ticket_data['approved_date'] : '' ?>" name="approved_date">
|
value="<?= isset($ticket_data['approved_date']) ? $ticket_data['approved_date'] : '' ?>" name="approved_date">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-6 approved" style="display: none;">
|
<div class="form-group col-md-3 approved" style="display: none;">
|
||||||
<label class="label-font-size" for="approved_letter">Approved Letter</label>
|
<label class="label-font-size" for="approved_letter">Approved Letter URL</label>
|
||||||
<input type="text" class="form-control" id="approved_letter" placeholder="Enter Approved Letter"
|
<input
|
||||||
value="<?= isset($ticket_data['approved_letter']) ? $ticket_data['approved_letter'] : '' ?>" name="approved_letter">
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="approved_letter"
|
||||||
|
placeholder="Enter Approved Letter URL"
|
||||||
|
value="<?= isset($ticket_data['approved_letter']) ? $ticket_data['approved_letter'] : '' ?>"
|
||||||
|
name="approved_letter">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3 approved" style="display: none;">
|
||||||
|
<label class="label-font-size" for="approved_letter_file">Approved Letter PDF</label>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
class="form-control"
|
||||||
|
id="approved_letter_file"
|
||||||
|
name="approved_letter_file"
|
||||||
|
accept=".pdf,application/pdf">
|
||||||
|
<small class="text-muted">Only PDF allowed.</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-6 approved" style="display: none;">
|
<div class="form-group col-md-6 approved" style="display: none;">
|
||||||
@ -453,12 +469,23 @@
|
|||||||
value="<?= isset($ticket_data['settled_date']) ? $ticket_data['settled_date'] : '' ?>" name="settled_date">
|
value="<?= isset($ticket_data['settled_date']) ? $ticket_data['settled_date'] : '' ?>" name="settled_date">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-6 settled" style="display: none;">
|
<div class="form-group col-md-3 settled" style="display: none;">
|
||||||
<label class="label-font-size" for="settle_letter">Settle Letter</label>
|
<label class="label-font-size" for="settle_letter">Settle Letter URL</label>
|
||||||
<input type="text" class="form-control" id="settle_letter" placeholder="Enter Settle Letter"
|
<input type="text" class="form-control" id="settle_letter" placeholder="Enter Settle Letter URL"
|
||||||
value="<?= isset($ticket_data['settle_letter']) ? $ticket_data['settle_letter'] : '' ?>" name="settle_letter">
|
value="<?= isset($ticket_data['settle_letter']) ? $ticket_data['settle_letter'] : '' ?>" name="settle_letter">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3 settled" style="display: none;">
|
||||||
|
<label class="label-font-size" for="settle_letter_file">Settle Letter PDF</label>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
class="form-control"
|
||||||
|
id="settle_letter_file"
|
||||||
|
name="settle_letter_file"
|
||||||
|
accept=".pdf,application/pdf">
|
||||||
|
<small class="text-muted">Only PDF allowed.</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-3 payment" style="display: none;">
|
<div class="form-group col-md-3 payment" style="display: none;">
|
||||||
<label class="label-font-size" for="pay_initiate_date">Payment Initiate Date</label>
|
<label class="label-font-size" for="pay_initiate_date">Payment Initiate Date</label>
|
||||||
<input type="text" class="form-control datepicker" id="pay_initiate_date" placeholder="Select Payment Initiate Date"
|
<input type="text" class="form-control datepicker" id="pay_initiate_date" placeholder="Select Payment Initiate Date"
|
||||||
@ -619,6 +646,8 @@
|
|||||||
console.log("extraFields", extraFields);
|
console.log("extraFields", extraFields);
|
||||||
claimStatusFieldChanges(extraFields);
|
claimStatusFieldChanges(extraFields);
|
||||||
handleTPARequired(tpa_id_for_hid_filed);
|
handleTPARequired(tpa_id_for_hid_filed);
|
||||||
|
// syncApprovedLetterInputs();
|
||||||
|
// syncSettleLetterInputs();
|
||||||
})
|
})
|
||||||
|
|
||||||
// function updateClaimStatusDisplay(value) {
|
// function updateClaimStatusDisplay(value) {
|
||||||
@ -723,6 +752,8 @@
|
|||||||
$field.prop('required', false);
|
$field.prop('required', false);
|
||||||
var $parentDiv = $field.closest("div");
|
var $parentDiv = $field.closest("div");
|
||||||
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
|
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
|
||||||
|
syncApprovedLetterInputs();
|
||||||
|
syncSettleLetterInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#claim_status_id').on('change', function() {
|
$('#claim_status_id').on('change', function() {
|
||||||
@ -774,6 +805,95 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Keep the file optional; URL remains conditionally required for approved state unless file is present.
|
||||||
|
$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;
|
||||||
|
const isSettledSectionVisible = $urlInput.closest('.settled').is(':visible');
|
||||||
|
|
||||||
|
$fileInput.prop('disabled', hasUrl);
|
||||||
|
$urlInput.prop('disabled', hasFile);
|
||||||
|
|
||||||
|
$fileInput.prop('required', false);
|
||||||
|
$urlInput.prop('required', isSettledSectionVisible && !hasFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
function enforceLetterPairRules() {
|
||||||
|
syncApprovedLetterInputs();
|
||||||
|
syncSettleLetterInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#approved_letter').on('input blur', function () {
|
||||||
|
enforceLetterPairRules();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#approved_letter_file').on('change', function () {
|
||||||
|
if (validateApprovedLetterPdf(this)) {
|
||||||
|
enforceLetterPairRules();
|
||||||
|
} else {
|
||||||
|
enforceLetterPairRules();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#settle_letter').on('input blur', function () {
|
||||||
|
enforceLetterPairRules();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#settle_letter_file').on('change', function () {
|
||||||
|
if (validateApprovedLetterPdf(this)) {
|
||||||
|
enforceLetterPairRules();
|
||||||
|
} else {
|
||||||
|
enforceLetterPairRules();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function claimStatusFieldChanges(fields) {
|
function claimStatusFieldChanges(fields) {
|
||||||
|
|
||||||
fields.forEach(function(fieldId) {
|
fields.forEach(function(fieldId) {
|
||||||
@ -789,6 +909,13 @@
|
|||||||
if ($label.length && !$label.find(".text-danger").length) {
|
if ($label.length && !$label.find(".text-danger").length) {
|
||||||
// $label.append(' <span class="text-danger">*</span>');
|
// $label.append(' <span class="text-danger">*</span>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -860,6 +987,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Re-apply URL/file pair rules after bulk required toggles.
|
||||||
|
enforceLetterPairRules();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on("input", function(event) {
|
$(document).on("input", function(event) {
|
||||||
@ -870,7 +1000,7 @@
|
|||||||
console.log('targetId', targetId);
|
console.log('targetId', targetId);
|
||||||
console.log('fields.includes(targetId)', fields.includes(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);
|
let $field = $("#" + targetId);
|
||||||
console.log('$field id', $field);
|
console.log('$field id', $field);
|
||||||
@ -904,9 +1034,14 @@
|
|||||||
$field.prop('required', false);
|
$field.prop('required', false);
|
||||||
var $parentDiv = $field.closest("div");
|
var $parentDiv = $field.closest("div");
|
||||||
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
|
$parentDiv.find("label[for='approved_description'] .text-danger").remove();
|
||||||
|
enforceLetterPairRules();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#ticket_form_data').on('submit', function() {
|
||||||
|
enforceLetterPairRules();
|
||||||
|
});
|
||||||
|
|
||||||
// function addRequiredFieldSymbol(field_name) {
|
// function addRequiredFieldSymbol(field_name) {
|
||||||
// // Find the field with the given name
|
// // Find the field with the given name
|
||||||
// var $field = $(`[name="${field_name}"]`);
|
// var $field = $(`[name="${field_name}"]`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user