From 0b7198a2854fdf51cc6edd5bddff5e92584798ee Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 17 Feb 2025 09:10:20 +0530 Subject: [PATCH] CHANGE_CLAIMS_MODULE_CHANGES : RV --- app/Controllers/TicketController.php | 159 +++++++++++++++++++++++++-- app/Models/TicketMasterModel.php | 8 +- app/Views/ticket_edit_onbording.php | 7 ++ app/Views/ticket_form_gmc.php | 52 ++++++++- app/Views/ticket_form_gpa.php | 56 +++++++++- app/Views/ticket_form_handler.php | 13 +++ 6 files changed, 276 insertions(+), 19 deletions(-) diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 599ad4dd..e1302f55 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -33,6 +33,7 @@ class TicketController extends BaseController protected $claimType; protected $claimStatus; protected $placeHolders; + protected $extraFields; protected $clientModel; protected $ticketMasterModel; @@ -73,7 +74,8 @@ class TicketController extends BaseController 1 => "In Person", 2 => "Courier", 3 => "Online Mode - Email", - 4 => "Online Mode - To TPA" + 4 => "Smart Service Desk", + 5 => "Direct to TPA" ]; $this->claimType = [ 1 => [ @@ -111,6 +113,30 @@ class TicketController extends BaseController '((POLICY_TYPE))' => 'policy_type', '((AUTO_QUERY_CONTENT))' => 'auto_query_content', ]; + $this->extraFields = [ + + 3 => ['raised_date'], + 4 => ['raised_date'], + 5 => ['claim_number', 'registration_date'], + 7 => ['query_received_date'], + 8 => ['denial_reason','denial_date'], + 9 => ['approved_amount','approved_date', 'approved_letter'], + 11 => ['utr_details', 'settled_date', 'settle_letter'], + 40 => ['approved_amount','approved_date', 'approved_letter'], + 44 => ['utr_details', 'settled_date', 'settle_letter'], + 30 => ['approved_amount','approved_date', 'approved_letter'], + 34 => ['utr_details', 'settled_date', 'settle_letter'], + 20 => ['approved_amount','approved_date', 'approved_letter'], + 24 => ['utr_details', 'settled_date', 'settle_letter'], + 14 => ['return_remark', 'awb_no_courier_name'], + 48 => ['return_remark', 'awb_no_courier_name'], + 59 => ['return_remark', 'awb_no_courier_name'], + 54 => ['return_remark', 'awb_no_courier_name'], + 13 => ['cancel_remark'], + 47 => ['cancel_remark'], + 53 => ['cancel_remark'], + 58 => ['cancel_remark'], + ]; $this->ticketMasterModel = new TicketMasterModel(); $this->claimStatus = new TicketClaimStatusModel(); @@ -260,7 +286,7 @@ class TicketController extends BaseController return $this->loadLayout('ticket_form_handler', $data); } - public function ticket_form_data($ticket_type) + public function ticket_form_data($ticket_type, $claim_status_id = null) { $this->myLogger->logme('error', "Fetching ticket form data for Ticket Type: $ticket_type"); @@ -294,11 +320,23 @@ class TicketController extends BaseController ->getResultArray(); // Fetch Claim Status - $data['claim_status'] = $this->claimStatus - ->select('*') - ->where(['is_active' => 1, 'ticket_type' => $ticket_type]) - ->get() - ->getResultArray(); + + if(empty($claim_status_id)){ + + if($ticket_type == 2){ + $claim_status_id = 15; + }else if($ticket_type == 3){ + $claim_status_id = 25; + }else if($ticket_type == 4){ + $claim_status_id = 35; + }else{ + $claim_status_id = 1; + } + } + + $data['claim_status'] = $this->transFormClaimStatus($claim_status_id, $ticket_type); + $data['extra_fields'] = $this->getExtraFields($data['claim_status']); + $data['extra_fields_array_for_validate'] = $this->getExtraFields($data['claim_status'], 1); if ($ticket_type == 1) { $data['claim_type'] = $this->claimType[1]; @@ -311,6 +349,73 @@ class TicketController extends BaseController return $data; } + //transform the claim status + public function transFormClaimStatus($claimStatusId, $ticket_type) + { + // Fetch the main claim status by ID + $claimStatusData = $this->claimStatus + ->select('*') + ->where(['is_active' => 1, 'ticket_type' => $ticket_type]) + ->where('id', $claimStatusId) + ->first(); + // dd($claimStatusData); + + // Initialize the filtered claim status array + $filteredClaimStatus = []; + + if (!empty($claimStatusData)) { + // Add the main claim status to the result + $filteredClaimStatus[] = $claimStatusData; + + // Decode the allowed_status JSON field + $filterClaimStatusIds = json_decode($claimStatusData['allowed_status'], true); + + // Fetch additional claim statuses if IDs exist + if (!empty($filterClaimStatusIds) && is_array($filterClaimStatusIds)) { + $additionalClaimStatuses = $this->claimStatus + ->select('*') + ->where(['is_active' => 1, 'ticket_type' => $ticket_type]) + ->whereIn('id', $filterClaimStatusIds) + ->get() + ->getResultArray(); + + // Merge additional claim statuses into the result + $filteredClaimStatus = array_merge($filteredClaimStatus, $additionalClaimStatuses); + } + } + + return $filteredClaimStatus; + } + + public function getExtraFields(array $claimStatus, $nonFilterArray = 0): array + { + $extra_fields = []; + + if($nonFilterArray == 1){ + + foreach ($claimStatus as $value) { + if (isset($this->extraFields[$value['id']])) { + if (!isset($extra_fields[$value['id']])) { + $extra_fields[$value['id']] = []; + } + $extra_fields[$value['id']] = array_merge($extra_fields[$value['id']], $this->extraFields[$value['id']]); + } + } + + }else{ + + foreach ($claimStatus as $value) { + if (isset($this->extraFields[$value['id']])) { + $extra_fields[] = $this->extraFields[$value['id']]; + } + } + + $extra_fields = array_values(array_unique(array_merge(...$extra_fields))); + } + + return $extra_fields; + } + public function view_ticket($ticket_id) { // $ticket_data = $this->ticketMasterModel->where('id', $ticket_id)->where('is_active', 1)->first(); @@ -322,7 +427,7 @@ class TicketController extends BaseController $template_data['mail_content'] = $this->replacePlaceholders($template_data['mail_content'], $ticket_data); $template_data['subject'] = $this->replacePlaceholders($template_data['subject'], $ticket_data); } - $data = $this->ticket_form_data($ticket_data['ticket_type_id']); + $data = $this->ticket_form_data($ticket_data['ticket_type_id'], $ticket_data['claim_status_id']); $data['ticket_data'] = $ticket_data; $data['reply_data'] = $template_data; $data['placeHolders'] = $this->placeHolders; @@ -430,6 +535,7 @@ class TicketController extends BaseController { $ticket_data = $this->request->getPost(); $ticket_data = $this->formatDateForClaim($ticket_data); + // $ticket_data = $this->getLastMatchedStatus($ticket_data, ); // print_rr($ticket_data); die; if ($ticket_data) { @@ -451,6 +557,7 @@ class TicketController extends BaseController $ticket_id = $this->request->getPost('ticket_master_id'); $ticket_data = $this->request->getPost(); $ticket_data = $this->formatDateForClaim($ticket_data); + $ticket_data['claim_status_id'] = $this->getLastMatchedStatus($ticket_data); // print_rr($ticket_data); die; $old_ticket_data = $this->ticketMasterModel->where('id', $ticket_id)->where('is_active', 1)->first(); @@ -1242,4 +1349,40 @@ class TicketController extends BaseController $this->myLogger->logme('error', "Head Mail can't be sent because ticket data is empty"); } } + + public function getLastMatchedStatus($incoming_form_values) + { + if (empty($incoming_form_values) || !isset($incoming_form_values['claim_status_id']) || !isset($incoming_form_values['extra_fields_array_for_validate'])) { + return null; + } + + $lastMatchedStatus = $incoming_form_values['claim_status_id']; + + // Use the provided `extra_fields_array_for_validate` from the incoming data + $statusMapping = json_decode($incoming_form_values['extra_fields_array_for_validate']); + + foreach ($statusMapping as $status => $requiredFields) { + // Ensure requiredFields is an array + if (!is_array($requiredFields)) { + $requiredFields = [$requiredFields]; + } + + // Check if all required fields exist and are not empty in the incoming form values + $allFieldsMatched = true; + foreach ($requiredFields as $field) { + if (!isset($incoming_form_values[$field]) || empty($incoming_form_values[$field])) { + $allFieldsMatched = false; + break; + } + } + + // Update the last matched status if all fields are validated + if ($allFieldsMatched) { + $lastMatchedStatus = $status; + } + } + + return $lastMatchedStatus; + } + } diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index fbcf696c..5587f943 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -64,7 +64,12 @@ class TicketMasterModel extends Model 'utr_details', 'settle_letter', 'is_head_approved', - ]; + + 'return_remark', + 'cancel_remark', + 'awb_no_courier_name', + + ]; // Callbacks @@ -126,6 +131,7 @@ class TicketMasterModel extends Model and ticket_mail_template.is_active = 1') ->where('ticket_master.id', $ticket_id) ->where('ticket_master.is_active', 1) + ->where('ticket_claim_status.is_active', 1) ->first(); return $template_data; diff --git a/app/Views/ticket_edit_onbording.php b/app/Views/ticket_edit_onbording.php index df9b3dd8..96064eb9 100644 --- a/app/Views/ticket_edit_onbording.php +++ b/app/Views/ticket_edit_onbording.php @@ -139,6 +139,13 @@ function submitClaimForm(event, form) { event.preventDefault(); + var isValid = $('#ticket_form_data').parsley().validate(); + + if (!isValid) { + toastr.warning('Form validation failed. Please check the required fields.', 'WARNING'); + return false; + } + const formAction = ''; // Show loader diff --git a/app/Views/ticket_form_gmc.php b/app/Views/ticket_form_gmc.php index f13c436b..c2543ca2 100644 --- a/app/Views/ticket_form_gmc.php +++ b/app/Views/ticket_form_gmc.php @@ -20,6 +20,7 @@ +
@@ -269,7 +270,7 @@ value="" name="approved_date">
- @@ -344,13 +361,16 @@ $(document).ready(function() { flatpickr("#approved_date", { dateFormat: "d/m/Y", allowInput: false }); flatpickr("#settled_date", { dateFormat: "d/m/Y", allowInput: false }); - updateClaimStatusDisplay("") + // updateClaimStatusDisplay("") + var extraFields = ; + console.log("extraFields", extraFields); + claimStatusFieldChanges(extraFields); }) function updateClaimStatusDisplay(value) { // Hide all sections first - $('.cda_ir, .settled, .approved, .rejected, .up_qdr, .up_cnu').hide(); + $('.cda_ir, .settled, .approved, .rejected, .up_qdr, .up_cnu, .canceled').hide(); // Show relevant section based on value if (value == 3 || value == 4) { // CDA / INFORMATION REQUIRED @@ -365,11 +385,35 @@ function updateClaimStatusDisplay(value) { $('.approved').show(); } else if (value == 11) { // SETTLED $('.settled').show(); + }else if (value == 13) { // CANCELLED + $('.canceled').show(); + }else if (value == 14) { // RETURNED + $('.returned').show(); } } $('#claim_status_id').on('change', function() { updateClaimStatusDisplay($(this).val()); + // claimStatusFieldChanges() }); +function claimStatusFieldChanges(fields) { + + fields.forEach(function(fieldId) { + var $field = $("#" + fieldId); + + if ($field.length) { + $field.prop('required', true); + + var $parentDiv = $field.closest("div"); + $parentDiv.show(); + + var $label = $parentDiv.find("label[for='" + fieldId + "']"); + if ($label.length && !$label.find(".text-danger").length) { + $label.append(' *'); + } + } + }); +} + \ No newline at end of file diff --git a/app/Views/ticket_form_gpa.php b/app/Views/ticket_form_gpa.php index d8d7b98d..b076322c 100644 --- a/app/Views/ticket_form_gpa.php +++ b/app/Views/ticket_form_gpa.php @@ -30,7 +30,7 @@ - +
@@ -209,7 +209,7 @@ value="" name="approved_date">
-
@@ -285,7 +302,11 @@ $(document).ready(function() { flatpickr("#approved_date", { dateFormat: "d/m/Y", allowInput: false }); flatpickr("#settled_date", { dateFormat: "d/m/Y", allowInput: false }); - updateClaimStatusDisplay("") + // updateClaimStatusDisplay("") + var extraFields = ; + console.log("extraFields", extraFields); + claimStatusFieldChanges(extraFields); + }) @@ -294,18 +315,41 @@ function updateClaimStatusDisplay(value) { console.log('value', value); // Hide all sections first - $('.settled, .approved').hide(); + $('.settled, .approved, .canceled, .returned').hide(); // Show relevant section based on value if (value == 20 || value == 30 || value == 40) { // APPROVED $('.approved').show(); } else if (value == 24 || value == 34 || value == 44) { // SETTLED $('.settled').show(); + }else if (value == 47 || value == 53 || value == 58) { // CANCELLED + $('.canceled').show(); + }else if (value == 48 || value == 54 || value == 59) { // RETURNED + $('.returned').show(); } } $('#claim_status_id').on('change', function() { - updateClaimStatusDisplay($(this).val()); + // updateClaimStatusDisplay($(this).val()); }); +function claimStatusFieldChanges(fields) { + + fields.forEach(function(fieldId) { + var $field = $("#" + fieldId); + + if ($field.length) { + $field.prop('required', true); + + var $parentDiv = $field.closest("div"); + $parentDiv.show(); + + var $label = $parentDiv.find("label[for='" + fieldId + "']"); + if ($label.length && !$label.find(".text-danger").length) { + $label.append(' *'); + } + } + }); +} + \ No newline at end of file diff --git a/app/Views/ticket_form_handler.php b/app/Views/ticket_form_handler.php index e668bde6..2eef1eb5 100644 --- a/app/Views/ticket_form_handler.php +++ b/app/Views/ticket_form_handler.php @@ -417,6 +417,13 @@ function submitClaimForm(event, form) { event.preventDefault(); + var isValid = $('#ticket_form_data').parsley().validate(); + + if (!isValid) { + toastr.warning('Form validation failed. Please check the required fields.', 'WARNING'); + return false; + } + const formAction = ''; // Show loader @@ -704,6 +711,12 @@ function setMemberData(input) { $(this).prop('selected', true); } }); + + if(tpaNo == ""){ + $('#claim_status_id').val(1) + }else{ + $('#claim_status_id').val(2) + } } $('#employee_data_points').on('change', function() {