FEAT_APPROVED_MAIL_SENT_FOR_PAYMENT_INTIATED
This commit is contained in:
parent
923c97c9cb
commit
553ba9069b
@ -817,6 +817,8 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) {
|
|||||||
$routes->post('saveIRDocsJson',"TicketController::saveIRDocsJson");
|
$routes->post('saveIRDocsJson',"TicketController::saveIRDocsJson");
|
||||||
$routes->get('getTpaClaimStatus',"ApiServiceController::getClaimStatus");
|
$routes->get('getTpaClaimStatus',"ApiServiceController::getClaimStatus");
|
||||||
$routes->post('manualTpaClaimPush',"ApiServiceController::manualTpaClaimPush");
|
$routes->post('manualTpaClaimPush',"ApiServiceController::manualTpaClaimPush");
|
||||||
|
$routes->match(['get', 'post'], 'getClaimTemplateData', 'TicketController::getClaimTemplateData');
|
||||||
|
$routes->post('uploadApprovedLetterFromReply', 'TicketController::uploadApprovedLetterFromReply');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Non-EB Claims
|
// Non-EB Claims
|
||||||
|
|||||||
@ -2438,7 +2438,7 @@ class TicketController extends BaseController
|
|||||||
|
|
||||||
//---- Email Trigger Part----------------------------------------------------------------------------------------------
|
//---- Email Trigger Part----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
public function constructMailContent($ticket_id)
|
public function constructMailContent($ticket_id, $status_id = null)
|
||||||
{
|
{
|
||||||
$this->myLogger->logme('error', "Constructing mail content for Ticket ID: $ticket_id");
|
$this->myLogger->logme('error', "Constructing mail content for Ticket ID: $ticket_id");
|
||||||
|
|
||||||
@ -2454,9 +2454,14 @@ class TicketController extends BaseController
|
|||||||
|
|
||||||
$this->myLogger->logme('error', "Fetched ticket data: " . json_encode($ticket_data));
|
$this->myLogger->logme('error', "Fetched ticket data: " . json_encode($ticket_data));
|
||||||
|
|
||||||
|
if (!empty($status_id)) {
|
||||||
|
$ticket_data['claim_status_id'] = (int) $status_id;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch Email Template Data
|
// Fetch Email Template Data
|
||||||
$template_data = $this->ticketMasterModel->getTemplateDataByTicketID($ticket_id);
|
$template_data = !empty($status_id)
|
||||||
// print_r($template_data); die;
|
? ($this->ticketMasterModel->getTemplateDataByStatusID((int) $status_id, (int) ($ticket_data['ticket_type_id'] ?? 0))[0] ?? null)
|
||||||
|
: $this->ticketMasterModel->getTemplateDataByTicketID($ticket_id);
|
||||||
|
|
||||||
if (!$template_data) {
|
if (!$template_data) {
|
||||||
$this->myLogger->logme('error', "No email template found for Claim Status ID: " . $ticket_data['claim_status_id']);
|
$this->myLogger->logme('error', "No email template found for Claim Status ID: " . $ticket_data['claim_status_id']);
|
||||||
@ -2628,7 +2633,7 @@ class TicketController extends BaseController
|
|||||||
'mail' => [$mail_data['emp_mail'], $ticket_data['emp_personal_mail'] ?? ""],
|
'mail' => [$mail_data['emp_mail'], $ticket_data['emp_personal_mail'] ?? ""],
|
||||||
'subject' => $mail_data['mail_subject'],
|
'subject' => $mail_data['mail_subject'],
|
||||||
'message' => $mail_data['mail_content'],
|
'message' => $mail_data['mail_content'],
|
||||||
'common' => [],
|
'common' => ['module' => "claim", 'pk' => $mail_data['ticket_id']],
|
||||||
'cc' => $acm_mails['common_mails'],
|
'cc' => $acm_mails['common_mails'],
|
||||||
'attachments' => []
|
'attachments' => []
|
||||||
];
|
];
|
||||||
@ -2826,7 +2831,7 @@ class TicketController extends BaseController
|
|||||||
'mail' => $template_data['emp_mail'],
|
'mail' => $template_data['emp_mail'],
|
||||||
'subject' => $template_data['subject'],
|
'subject' => $template_data['subject'],
|
||||||
'message' => $template_data['mail_content'],
|
'message' => $template_data['mail_content'],
|
||||||
'common' => [],
|
'common' => ['module' => "claim", 'pk' => $ticket_id],
|
||||||
'cc' => $acm_mails['common_mails'],
|
'cc' => $acm_mails['common_mails'],
|
||||||
'attachments' => []
|
'attachments' => []
|
||||||
];
|
];
|
||||||
@ -2987,7 +2992,7 @@ class TicketController extends BaseController
|
|||||||
'mail' => $head_mail['email'],
|
'mail' => $head_mail['email'],
|
||||||
'subject' => $subject,
|
'subject' => $subject,
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'common' => [],
|
'common' => ['module' => "claim", 'pk' => $ticket_data['id']],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->sendTrigger($emailData);
|
$this->sendTrigger($emailData);
|
||||||
@ -3722,7 +3727,7 @@ class TicketController extends BaseController
|
|||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertTermsToDisplay(array $data)
|
public function convertTermsToDisplay(array $data)
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
@ -3902,6 +3907,106 @@ class TicketController extends BaseController
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getClaimTemplateData()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$ticket_id = $this->request->getPost('ticket_id') ?? $this->request->getGet('ticket_id');
|
||||||
|
$status_id = $this->request->getPost('status_id') ?? $this->request->getGet('status_id');
|
||||||
|
|
||||||
|
if (empty($ticket_id) || empty($status_id)) {
|
||||||
|
return $this->respond(['status' => false, 'message' => 'Ticket ID and Status ID are required'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail_content = $this->constructMailContent($ticket_id, $status_id);
|
||||||
|
if ($mail_content) {
|
||||||
|
return $this->respond(['status' => true, 'data' => $mail_content], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => false, 'message' => 'Failed to construct mail content'], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->myLogger->logme('error', 'Error in getClaimTemplateData: ' . $e->getMessage() . ' in file ' . $e->getFile() . ' on line ' . $e->getLine() . $e->getTraceAsString());
|
||||||
|
return $this->respond(['status' => false, 'message' => 'An error occurred while fetching template data'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uploadApprovedLetterFromReply()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$ticket_id = $this->request->getPost('ticket_id');
|
||||||
|
$status_id = $this->request->getPost('status_id');
|
||||||
|
$approvedLetterUrl = trim((string) $this->request->getPost('approved_letter'));
|
||||||
|
$approvedLetterFile = $this->request->getFile('approved_letter_file');
|
||||||
|
|
||||||
|
if (empty($ticket_id) || empty($status_id)) {
|
||||||
|
return $this->respond(['status' => false, 'message' => 'Ticket ID and Status ID are required'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((int) $status_id !== 9) {
|
||||||
|
return $this->respond(['status' => false, 'message' => 'Approved letter upload is allowed only for APPROVED status'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ticket_data = $this->ticketMasterModel->getTicketDataByTicketID($ticket_id);
|
||||||
|
if (empty($ticket_data)) {
|
||||||
|
return $this->respond(['status' => false, 'message' => 'Ticket not found'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($ticket_data['approved_letter'])) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Approved letter already available',
|
||||||
|
'data' => ['approved_letter' => $ticket_data['approved_letter']],
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasApprovedLetterFile = $approvedLetterFile !== null
|
||||||
|
&& $approvedLetterFile->isValid()
|
||||||
|
&& $approvedLetterFile->getError() !== UPLOAD_ERR_NO_FILE;
|
||||||
|
|
||||||
|
if ($approvedLetterUrl !== '' && $hasApprovedLetterFile) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Provide either Approved Letter URL or Approved Letter PDF file, not both.',
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($approvedLetterUrl !== '' && !$this->isClaimUploadUrl($approvedLetterUrl)) {
|
||||||
|
return $this->respond(['status' => false, 'message' => 'Approved Letter URL format is invalid.'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($approvedLetterUrl === '' && !$hasApprovedLetterFile) {
|
||||||
|
return $this->respond(['status' => false, 'message' => 'Provide Approved Letter URL or Approved Letter PDF file.'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$approvedLetterValue = $approvedLetterUrl;
|
||||||
|
if ($hasApprovedLetterFile) {
|
||||||
|
$uploadResult = $this->uploadApprovedLetterPdf($approvedLetterFile, 'Approved Letter');
|
||||||
|
if (!($uploadResult['status'] ?? false)) {
|
||||||
|
return $this->respond(['status' => false, 'message' => $uploadResult['message'] ?? 'Invalid Approved Letter file.'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$approvedLetterValue = $this->createApprovedLetterFileUrl(
|
||||||
|
(int) $ticket_id,
|
||||||
|
(int) ($ticket_data['ticket_type_id'] ?? 1),
|
||||||
|
$uploadResult['data'],
|
||||||
|
'APPROVED_LETTER_PDF'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->ticketMasterModel
|
||||||
|
->where('id', (int) $ticket_id)
|
||||||
|
->set(['approved_letter' => $approvedLetterValue])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => true,
|
||||||
|
'message' => 'Approved letter uploaded successfully',
|
||||||
|
'data' => ['approved_letter' => $approvedLetterValue],
|
||||||
|
], 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->myLogger->logme('error', 'Error in uploadApprovedLetterFromReply: ' . $e->getMessage() . ' in file ' . $e->getFile() . ' on line ' . $e->getLine() . $e->getTraceAsString());
|
||||||
|
return $this->respond(['status' => false, 'message' => 'An error occurred while uploading approved letter'], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -------- CLAIM DUMP UPLOAD ----------------------------------------------------------------------------------------------
|
// -------- CLAIM DUMP UPLOAD ----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -133,17 +133,20 @@ class TicketMasterModel extends Model
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplateDataByStatusID($claim_status_id)
|
public function getTemplateDataByStatusID($claim_status_id, $ticket_type_id = null)
|
||||||
{
|
{
|
||||||
|
$builder = $this->db->table('ticket_claim_status tcs')
|
||||||
$template_data = $this->table('ticket_claim_status')
|
|
||||||
->select('ticket_mail_template.*')
|
->select('ticket_mail_template.*')
|
||||||
->join('ticket_mail_template', 'ticket_mail_template.trigger_type = ticket_claim_status.trigger_type')
|
->join('ticket_mail_template', 'ticket_mail_template.trigger_type = tcs.trigger_type')
|
||||||
->where('ticket_mail_template.is_active', 1)
|
->where('ticket_mail_template.is_active', 1)
|
||||||
->where('ticket_claim_status.is_active', 1)
|
->where('tcs.id', $claim_status_id)
|
||||||
->where('ticket_claim_status.id', $claim_status_id)
|
->where('tcs.is_active', 1);
|
||||||
->get()
|
|
||||||
->getResultArray();
|
if ($ticket_type_id !== null && $ticket_type_id !== '') {
|
||||||
|
$builder->where('ticket_mail_template.ticket_type', $ticket_type_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$template_data = $builder->get()->getResultArray();
|
||||||
|
|
||||||
return $template_data;
|
return $template_data;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,27 @@
|
|||||||
<form role="form" class="parsley-examples" style="color:black;" method="post" id="ticket_reply_form" enctype="multipart/form-data">
|
<form role="form" class="parsley-examples" style="color:black;" method="post" id="ticket_reply_form" enctype="multipart/form-data">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$showApprovedStatusDropdown =
|
||||||
|
isset($ticket_data['claim_status_id'], $ticket_data['ticket_type_id']) && (int) $ticket_data['claim_status_id'] === 10 && (int) $ticket_data['ticket_type_id'] === 1 &&
|
||||||
|
(
|
||||||
|
(isset($ticket_data['claim_created_by']) && $ticket_data['claim_created_by'] == 'TPA') ||
|
||||||
|
(array_key_exists('tpa_claim_push_reference_no', $ticket_data) && $ticket_data['tpa_claim_push_reference_no'] !== null)
|
||||||
|
);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php if ($showApprovedStatusDropdown): ?>
|
||||||
|
<div class="form-group col-md-4">
|
||||||
|
<label for="status_back_option">Status</label>
|
||||||
|
<select class="form-control" id="status_back_option">
|
||||||
|
<option value="">Select</option>
|
||||||
|
<option value="9">APPROVED</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<!-- Email To Field -->
|
<!-- Email To Field -->
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-4">
|
||||||
<label for="emp_mail_for_to">To</label>
|
<label for="emp_mail_for_to">To</label>
|
||||||
@ -46,10 +67,140 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.approved-letter-mode-option {
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.approved-letter-mode-option.selected {
|
||||||
|
border-color: #0a8794;
|
||||||
|
background-color: #f2fbfc;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="modal fade" id="approvedLetterUploadModal" tabindex="-1" role="dialog" aria-labelledby="approvedLetterUploadModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title" id="approvedLetterUploadModalLabel">Upload Approved Letter</h4>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="approved-letter-mode-option selected" onclick="selectApprovedLetterOption(this, 'approved_letter_mode_url')">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="approved_letter_mode" id="approved_letter_mode_url" value="url" checked>
|
||||||
|
<label class="form-check-label" for="approved_letter_mode_url">Approved Letter URL</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="approved-letter-mode-option" onclick="selectApprovedLetterOption(this, 'approved_letter_mode_pdf')">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="approved_letter_mode" id="approved_letter_mode_pdf" value="pdf">
|
||||||
|
<label class="form-check-label" for="approved_letter_mode_pdf">Approved Letter PDF</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="approved_letter_url_block">
|
||||||
|
<label for="approved_letter_reply_url">Approved Letter URL</label>
|
||||||
|
<input type="text" class="form-control" id="approved_letter_reply_url" placeholder="Enter Approved Letter URL">
|
||||||
|
<small class="text-danger d-none" id="approved_letter_reply_url_error"></small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group mb-0" id="approved_letter_pdf_block" style="display:none;">
|
||||||
|
<label for="approved_letter_reply_file">Approved Letter PDF</label>
|
||||||
|
<input type="file" class="form-control" id="approved_letter_reply_file" accept=".pdf,application/pdf">
|
||||||
|
<small class="text-muted">Only PDF is allowed for file upload.</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||||
|
<button type="button" class="btn btn-primary" id="uploadApprovedLetterBtn">Upload</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
|
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
|
||||||
|
|
||||||
|
function selectApprovedLetterOption(element, inputId) {
|
||||||
|
$('.approved-letter-mode-option').removeClass('selected');
|
||||||
|
$(element).addClass('selected');
|
||||||
|
$('#' + inputId).prop('checked', true).trigger('change');
|
||||||
|
}
|
||||||
|
|
||||||
|
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';
|
||||||
|
|
||||||
|
if (!isPdfByName || !isPdfByType) {
|
||||||
|
fileInput.value = '';
|
||||||
|
toastr.warning('Only PDF files are allowed for Approved Letter.', 'Warning');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidApprovedLetterUrl(urlValue) {
|
||||||
|
const url = (urlValue || '').trim();
|
||||||
|
if (!url) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const normalizedUrl = /^https?:\/\//i.test(url) ? url : `https://${url}`;
|
||||||
|
const parsed = new URL(normalizedUrl);
|
||||||
|
if (!['http:', 'https:'].includes(parsed.protocol)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const host = (parsed.hostname || '').toLowerCase();
|
||||||
|
if (!host) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (host === 'localhost') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(host)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return host.includes('.');
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setApprovedLetterUrlError(message) {
|
||||||
|
const $urlInput = $('#approved_letter_reply_url');
|
||||||
|
const $errorEl = $('#approved_letter_reply_url_error');
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
$urlInput.addClass('is-invalid');
|
||||||
|
$errorEl.text(message).removeClass('d-none');
|
||||||
|
} else {
|
||||||
|
$urlInput.removeClass('is-invalid');
|
||||||
|
$errorEl.text('').addClass('d-none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const editorConfig = {
|
const editorConfig = {
|
||||||
buttons: toolbar.concat(['fontsize']),
|
buttons: toolbar.concat(['fontsize']),
|
||||||
fontsize: [8, 10, 12, 14, 16, 18, 20, 22, 24], // Customize font sizes
|
fontsize: [8, 10, 12, 14, 16, 18, 20, 22, 24], // Customize font sizes
|
||||||
@ -71,6 +222,13 @@ const editorConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
const replyTicketId = `<?= isset($ticket_data['id']) ? (int) $ticket_data['id'] : 0 ?>`;
|
||||||
|
let replyApprovedLetter = <?= json_encode($ticket_data['approved_letter'] ?? null) ?>;
|
||||||
|
console.log('Approved Letter from server:', replyApprovedLetter);
|
||||||
|
|
||||||
|
function hasApprovedLetterValue(value) {
|
||||||
|
return value !== null && value !== undefined && String(value).trim() !== '';
|
||||||
|
}
|
||||||
|
|
||||||
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
|
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
|
||||||
|
|
||||||
@ -134,6 +292,216 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function loadClaimTemplateForStatus(ticketId, statusId) {
|
||||||
|
if (!ticketId || !statusId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '<?= base_url('/ticket/getClaimTemplateData') ?>',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
ticket_id: ticketId,
|
||||||
|
status_id: statusId
|
||||||
|
},
|
||||||
|
success: function(res) {
|
||||||
|
if (res && res.status && res.data) {
|
||||||
|
if (typeof res.data.subject !== 'undefined') {
|
||||||
|
$('#mail_subject').val(res.data.subject || '');
|
||||||
|
}
|
||||||
|
if (typeof res.data.message !== 'undefined') {
|
||||||
|
editor.value = res.data.message || '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toastr.warning(res.message || 'Failed to load mail template', 'Warning');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
toastr.error('Unable to fetch mail template.', 'Error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openApprovedLetterUploadModalAndHandle(ticketId, statusId) {
|
||||||
|
const dfd = $.Deferred();
|
||||||
|
const $modal = $('#approvedLetterUploadModal');
|
||||||
|
const $modeUrl = $('#approved_letter_mode_url');
|
||||||
|
const $modePdf = $('#approved_letter_mode_pdf');
|
||||||
|
const $urlBlock = $('#approved_letter_url_block');
|
||||||
|
const $pdfBlock = $('#approved_letter_pdf_block');
|
||||||
|
const $urlInput = $('#approved_letter_reply_url');
|
||||||
|
const $fileInput = $('#approved_letter_reply_file');
|
||||||
|
const $uploadBtn = $('#uploadApprovedLetterBtn');
|
||||||
|
const approvedLetterModalEl = document.getElementById('approvedLetterUploadModal');
|
||||||
|
const approvedLetterModalInstance = new bootstrap.Modal(approvedLetterModalEl, {
|
||||||
|
backdrop: 'static',
|
||||||
|
keyboard: false
|
||||||
|
});
|
||||||
|
|
||||||
|
$urlInput.val('');
|
||||||
|
$fileInput.val('');
|
||||||
|
$modeUrl.prop('checked', true).trigger('change');
|
||||||
|
$('.approved-letter-mode-option').removeClass('selected');
|
||||||
|
$('.approved-letter-mode-option').first().addClass('selected');
|
||||||
|
$uploadBtn.prop('disabled', false);
|
||||||
|
approvedLetterModalInstance.show();
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
$uploadBtn.off('click.approvedUpload');
|
||||||
|
$modal.off('hidden.bs.modal.approvedUpload');
|
||||||
|
$modeUrl.off('change.approvedUpload');
|
||||||
|
$modePdf.off('change.approvedUpload');
|
||||||
|
}
|
||||||
|
|
||||||
|
$modal.on('hidden.bs.modal.approvedUpload', function() {
|
||||||
|
cleanup();
|
||||||
|
if (dfd.state() === 'pending') {
|
||||||
|
dfd.reject('Upload cancelled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$modeUrl.on('change.approvedUpload', function() {
|
||||||
|
if ($(this).is(':checked')) {
|
||||||
|
$urlBlock.show();
|
||||||
|
$pdfBlock.hide();
|
||||||
|
$fileInput.val('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$modePdf.on('change.approvedUpload', function() {
|
||||||
|
if ($(this).is(':checked')) {
|
||||||
|
$pdfBlock.show();
|
||||||
|
$urlBlock.hide();
|
||||||
|
$urlInput.val('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$urlInput.on('input.approvedUpload', function() {
|
||||||
|
const currentValue = $.trim($(this).val());
|
||||||
|
if (currentValue === '') {
|
||||||
|
setApprovedLetterUrlError('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isValidApprovedLetterUrl(currentValue)) {
|
||||||
|
setApprovedLetterUrlError('Approved Letter URL format is invalid.');
|
||||||
|
} else {
|
||||||
|
setApprovedLetterUrlError('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$urlInput.on('blur.approvedUpload', function() {
|
||||||
|
const currentValue = $.trim($(this).val());
|
||||||
|
if (currentValue === '') {
|
||||||
|
setApprovedLetterUrlError('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isValidApprovedLetterUrl(currentValue)) {
|
||||||
|
setApprovedLetterUrlError('Approved Letter URL format is invalid.');
|
||||||
|
} else {
|
||||||
|
setApprovedLetterUrlError('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$fileInput.on('change.approvedUpload', function() {
|
||||||
|
validateApprovedLetterPdf(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
$uploadBtn.on('click.approvedUpload', function() {
|
||||||
|
const selectedMode = $('input[name="approved_letter_mode"]:checked').val();
|
||||||
|
const urlValue = $.trim($urlInput.val());
|
||||||
|
const file = $fileInput[0].files && $fileInput[0].files[0] ? $fileInput[0].files[0] : null;
|
||||||
|
|
||||||
|
if (selectedMode === 'url' && !urlValue) {
|
||||||
|
setApprovedLetterUrlError('Please enter Approved Letter URL.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedMode === 'url' && !isValidApprovedLetterUrl(urlValue)) {
|
||||||
|
setApprovedLetterUrlError('Approved Letter URL format is invalid.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setApprovedLetterUrlError('');
|
||||||
|
|
||||||
|
if (selectedMode === 'pdf' && !file) {
|
||||||
|
toastr.warning('Please select Approved Letter PDF.', 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedMode === 'pdf' && file) {
|
||||||
|
if (!validateApprovedLetterPdf($fileInput[0])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('ticket_id', ticketId);
|
||||||
|
formData.append('status_id', statusId);
|
||||||
|
formData.append('approved_letter', selectedMode === 'url' ? urlValue : '');
|
||||||
|
if (selectedMode === 'pdf' && file) {
|
||||||
|
formData.append('approved_letter_file', file);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadBtn.prop('disabled', true);
|
||||||
|
$.ajax({
|
||||||
|
url: '<?= base_url('/ticket/uploadApprovedLetterFromReply') ?>',
|
||||||
|
type: 'POST',
|
||||||
|
data: formData,
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(res) {
|
||||||
|
if (res && res.status) {
|
||||||
|
replyApprovedLetter = (res.data && res.data.approved_letter) ? res.data.approved_letter : replyApprovedLetter;
|
||||||
|
toastr.success(res.message || 'Approved letter uploaded successfully', 'Success');
|
||||||
|
cleanup();
|
||||||
|
approvedLetterModalInstance.hide();
|
||||||
|
dfd.resolve();
|
||||||
|
} else {
|
||||||
|
$uploadBtn.prop('disabled', false);
|
||||||
|
toastr.error((res && res.message) ? res.message : 'Approved letter upload failed', 'Error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
$uploadBtn.prop('disabled', false);
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
toastr.error('Unable to upload approved letter.', 'Error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return dfd.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleStatusTemplateFlow() {
|
||||||
|
const selectedStatusId = $('#status_back_option').val();
|
||||||
|
if (!selectedStatusId || !replyTicketId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (String(selectedStatusId) === '9' && !hasApprovedLetterValue(replyApprovedLetter)) {
|
||||||
|
openApprovedLetterUploadModalAndHandle(replyTicketId, selectedStatusId)
|
||||||
|
.done(function() {
|
||||||
|
loadClaimTemplateForStatus(replyTicketId, selectedStatusId);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadClaimTemplateForStatus(replyTicketId, selectedStatusId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#status_back_option').on('change', function() {
|
||||||
|
handleStatusTemplateFlow();
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($('#status_back_option').length && hasApprovedLetterValue(replyApprovedLetter)) {
|
||||||
|
const selectedStatusId = $('#status_back_option').val();
|
||||||
|
if (selectedStatusId) {
|
||||||
|
loadClaimTemplateForStatus(replyTicketId, selectedStatusId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function insertAtCursor(input, textToInsert) {
|
function insertAtCursor(input, textToInsert) {
|
||||||
if (document.selection) {
|
if (document.selection) {
|
||||||
input.focus();
|
input.focus();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user