diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 65b7ba3f..9165cc0f 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -754,7 +754,7 @@ class EmployeeRestController extends AdminController $result = $empServiceController->excelFileFormatValidation(['file_id' => $file_id]); if (isset($result['error_summary']) && count($result['error_summary'])) { $result = $empServiceController->getExcelErrorData($file_id); - return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "file upload failed with errors", 'data' => $result], 200); + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "The data format is invalid. Click 'Next' to view details.", 'data' => $result], 200); } @@ -2573,95 +2573,117 @@ class EmployeeRestController extends AdminController public function claimView() { - $ticket_id = $this->request->getGet('ticket_id'); - $ticketController = new TicketController; - $data['ticket_history'] = $ticketController->ticketHistory($ticket_id); - $data['claims_data'] = $this->ticketMaster->getTicketDataByTicketID($ticket_id); - $data['ticket_data'] = $ticketController->getMoreInfo($requestFrom = 'rest', $ticket_id); + try { - // $ticketData = $data['ticket_data']; - // $ticketHistory = $data['ticket_history']; + $ticket_id = $this->request->getGet('ticket_id'); + $ticketController = new TicketController; + $data['ticket_history'] = $ticketController->ticketHistory($ticket_id); + $data['claims_data'] = $this->ticketMaster->getTicketDataByTicketID($ticket_id); + $data['ticket_data'] = $ticketController->getMoreInfo($requestFrom = 'rest', $ticket_id); - $ticketClaimStatus = $this->claimStatusModel->select('claim_status, display_name')->where('display_name is not null')->where('is_active', 1)->findAll(); - $status_list = array_column($ticketClaimStatus, 'display_name', 'claim_status'); - - $data['ticket_data'] = array_fill_keys(array_keys($data['ticket_data']), []); + // $ticketData = $data['ticket_data']; + // $ticketHistory = $data['ticket_history']; + // print_r($ticketHistory); die; + $currentClaimStatus = $this->claimStatusModel->select("claim_status")->where('id', $data['claims_data']['claim_status_id'])->where('is_active', 1)->first(); + $ticketClaimStatus = $this->claimStatusModel->select('claim_status, display_name')->where('display_name is not null')->where('is_active', 1)->findAll(); + $status_list = array_column($ticketClaimStatus, 'display_name', 'claim_status'); + // print_r($currentClaimStatus); die; - // Loop through ticket_data - foreach ($data['ticket_data'] as $status => &$fields) { - // Search ticket_history for matching old_status_value - foreach ($data['ticket_history'] as $history) { + $data['ticket_data'] = array_fill_keys(array_keys($data['ticket_data']), []); - if ($history['old_status_value'] === $status) { - // Attach modified_by and created_at - // $fields['modified_by'] = $history['modified_by']; - $fields['modified_by'] = ""; - $fields['modified_at'] = date('d-m-Y h:i A', strtotime($history['created_at'])); - // Break after first match (assuming latest entry is enough) - break; + // Loop through ticket_data + foreach ($data['ticket_data'] as $status => &$fields) { + // Search ticket_history for matching old_status_value + foreach ($data['ticket_history'] as $history) { + + if ($history['old_status_value'] === $status) { + // Attach modified_by and created_at + // $fields['modified_by'] = $history['modified_by']; + $fields['modified_by'] = ""; + $fields['modified_at'] = date('d-m-Y h:i A', strtotime($history['created_at'])); + // Break after first match (assuming latest entry is enough) + break; + } } } - } - $new_ticket_data = []; + $data['ticket_data'][$currentClaimStatus['claim_status']]['modified_by'] = ""; + $data['ticket_data'][$currentClaimStatus['claim_status']]['modified_at'] = $formatted = date('d-m-Y h:i A', strtotime($data['claims_data']['updated_at'])); - foreach ($data['ticket_data'] as $oldKey => $value) { + $new_ticket_data = []; - // Only process if key exists in status_list - if (!isset($status_list[$oldKey])) { - continue; // skip and do NOT add to new array + foreach ($data['ticket_data'] as $oldKey => $value) { + + // Only process if key exists in status_list + if (!isset($status_list[$oldKey])) { + continue; // skip and do NOT add to new array + } + + // Get new key based on mapping + $newKey = $status_list[$oldKey]; + + // Avoid duplicates + if (!isset($new_ticket_data[$newKey])) { + $new_ticket_data[$newKey] = $value; + } } - // Get new key based on mapping - $newKey = $status_list[$oldKey]; + uasort($new_ticket_data, function ($a, $b) { + $timeA = \DateTime::createFromFormat('d-m-Y h:i A', $a['modified_at']); + $timeB = \DateTime::createFromFormat('d-m-Y h:i A', $b['modified_at']); + return $timeA <=> $timeB; // Ascending + }); - // Avoid duplicates - if (!isset($new_ticket_data[$newKey])) { - $new_ticket_data[$newKey] = $value; - } - } - - uasort($new_ticket_data, function ($a, $b) { - $timeA = \DateTime::createFromFormat('d-m-Y h:i A', $a['modified_at']); - $timeB = \DateTime::createFromFormat('d-m-Y h:i A', $b['modified_at']); - return $timeA <=> $timeB; // Ascending - }); - - $data['ticket_data'] = $new_ticket_data; + $data['ticket_data'] = $new_ticket_data; - $ticketMesssageModel = new TicketMessageModel(); - $ticket_message = $ticketMesssageModel - ->where('is_active', 1) - ->where('sender', "user") - ->where('ticket_id', $ticket_id) - ->orderBy('id', "desc") - ->first(); - - $claim_file_urls = []; - - if (isset($ticket_message['id'])) { - - $claimFiles = new ClaimFilesModel(); - $claim_files_data = $claimFiles - ->select('id as claim_file_id, doc_name as claim_file_name') + $ticketMesssageModel = new TicketMessageModel(); + $ticket_message = $ticketMesssageModel ->where('is_active', 1) - ->where('file_type', 2) + ->where('sender', "user") ->where('ticket_id', $ticket_id) - ->where('ticket_message_id', $ticket_message['id']) - ->findAll(); + ->orderBy('id', "desc") + ->first(); - foreach ($claim_files_data as &$value) { - $value['url'] = base_url('downloadClaimFile/') . $value['claim_file_id']; - $claim_file_urls[] = $value; + $claim_file_urls = []; + + if (isset($ticket_message['id'])) { + + $claimFiles = new ClaimFilesModel(); + $claim_files_data = $claimFiles + ->select('id as claim_file_id, doc_name as claim_file_name') + ->where('is_active', 1) + ->where('file_type', 2) + ->where('ticket_id', $ticket_id) + ->where('ticket_message_id', $ticket_message['id']) + ->findAll(); + + foreach ($claim_files_data as &$value) { + $value['url'] = base_url('downloadClaimFile/') . $value['claim_file_id']; + $claim_file_urls[] = $value; + } + unset($value); } - unset($value); + + $data['claim_files'] = $claim_file_urls; + + return $this->respond(['status' => (count($data) ? 'success' : 'failed'), 'code' => (count($data) ? 200 : 404), 'data' => $data,], 200); + + } catch (\Throwable $th) { + $this->myLogger->logme("error", 'claim_view' .($th->getMessage() . ' --- ' . $th->getLine() . '----' . $th->getTraceAsString())); + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => "", 'error_data' => $errorData], 500); } - - $data['claim_files'] = $claim_file_urls; - - return $this->respond(['status' => (count($data) ? 'success' : 'failed'), 'code' => (count($data) ? 200 : 404), 'data' => $data,], 200); }