diff --git a/app/Controllers/BDSReportController.php b/app/Controllers/BDSReportController.php index 355df367..38c5ecd4 100644 --- a/app/Controllers/BDSReportController.php +++ b/app/Controllers/BDSReportController.php @@ -937,7 +937,13 @@ class BDSReportController extends AdminController } } - public function bdsTATReport() + /** New arugument Introduced Named as "$isInternalCalled" + * Functional Based called means $isInternalCalled is True. + * Output returning as Array + * Route Based called means $isInternalCalled is False. becoz this is External Call + * Output returning as Page + */ + public function bdsTATReport($isInternalCalled = false) { $sql = " SELECT @@ -1010,9 +1016,8 @@ class BDSReportController extends AdminController // dd(db_connect()->getLastQuery(),$result); $data['data'] = $result; // dd($data, get_role_id(), ENROLLMENT_TEAM_ID, user_team()); - // return $this->loadLayout('bds_tat_wise_report', $data); - - return $result; + if ($isInternalCalled) { return $result; } + return $this->loadLayout('bds_tat_wise_report', $data); } public function accountMangerStatusBDSReport() @@ -1141,7 +1146,7 @@ class BDSReportController extends AdminController if ($report_type == 1){ $data['page_title'] = "BDS TAT Report"; - $data['data'] = $this->bdsTATReport(); + $data['data'] = $this->bdsTATReport(true); // Functional Based called means True }else if ($report_type == 2){ $data['page_title'] = "Account Manager Status Report"; diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index ec046563..ea0e4fb8 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -779,32 +779,63 @@ class UserController extends AdminController } } + // public function downloadIncentivesFile($file_id) + // { + // try { + // $result = $this->partnerManagerIncentiveFileModel->where('id', $file_id)->first(); + + // if (!$result || empty($result['incentive_file_name'])) { + // throw new \Exception("File Name Not Found"); + // } + + // $incentive_file_name = $result['incentive_file_name']; + // $file_name = basename($incentive_file_name); + // $filePath = WRITEPATH . 'uploads/incentives/' . $file_name; + + // if (file_exists($filePath)) { + // return $this->response->download($filePath, null); + // } else { + // throw new \Exception("File Not Found"); + // } + + // } catch (\Exception $e) { + + // $this->myLogger->logme('error', $e->getMessage()); + + // // Show 404 error view + // $data['message'] = $e->getMessage(); + // return view('errors/404', $data); + // } + // } + public function downloadIncentivesFile($file_id) { try { $result = $this->partnerManagerIncentiveFileModel->where('id', $file_id)->first(); if (!$result || empty($result['incentive_file_name'])) { - throw new \Exception("File Name Not Found"); + throw new \Exception("File Name Not Found for ID {$file_id}"); } $incentive_file_name = $result['incentive_file_name']; $file_name = basename($incentive_file_name); $filePath = WRITEPATH . 'uploads/incentives/' . $file_name; - if (file_exists($filePath)) { - return $this->response->download($filePath, null); - } else { - throw new \Exception("File Not Found"); + if (!file_exists($filePath)) { + throw new \Exception("File Not Found: {$file_name}"); } - } catch (\Exception $e) { - + return $this->response->download($filePath, null); + } catch (\Throwable $e) { + // Catch all kinds of exceptions $this->myLogger->logme('error', $e->getMessage()); - // Show 404 error view - $data['message'] = $e->getMessage(); - return view('errors/404', $data); + // Return proper 404 for missing file, else 500 for unexpected error + if (str_contains($e->getMessage(), 'Not Found')) { + return $this->response->setStatusCode(404)->setBody($e->getMessage()); + } + + return $this->response->setStatusCode(500)->setBody('Internal Server Error'); } } diff --git a/app/Views/UserList.php b/app/Views/UserList.php index 82441b22..7561a427 100755 --- a/app/Views/UserList.php +++ b/app/Views/UserList.php @@ -1550,9 +1550,10 @@ table.dataTable tbody td { container.append(`
No Files have been Uploaded
`); } }, - error: function(xhr) { + error: function (xhr, status, errorThrown) { container.html(`
No Files have been Uploaded
`); - toastr.error('Server error occurred.', 'Error'); + console.log("Error: " + xhr.status + " - " + errorThrown); + if (xhr.status !== 404) toastr.error(errorThrown || xhr.responseText || 'Something went wrong', 'Error'); } }); } diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 65cb4d9d..5fe38d18 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -62,7 +62,7 @@ - + @@ -71,15 +71,15 @@ @@ -1254,16 +1254,16 @@ } /* Cancel Bootstrap's .form-control for file inputs */ - input[type="file"].form-control { - height: auto !important; + /* input[type="file"].form-control { */ + /* height: auto !important;*/ /* remove forced height */ - padding: initial !important; + /* padding: initial !important;*/ /* reset padding */ - font-size: inherit !important; + /* font-size: inherit !important;*/ /* reset font size */ - line-height: normal !important; + /* line-height: normal !important;*/ /* reset line height */ - } + /* } */ /* Apply to Select2 (single select) */