From 44a8af4e2e425efde455606a5438139d664e641e Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Thu, 28 Aug 2025 15:29:34 +0530 Subject: [PATCH] CHANGE_TicketHistory --- app/Config/Routes.php | 4 +- app/Controllers/ThzController.php | 113 ++++++++---- app/Models/ThzHistoryModel.php | 45 +++++ ...{TicketTypesModel.php => ThzTypeModel.php} | 4 +- app/Views/layout/header.php | 33 ++++ app/Views/thz_list.php | 162 ++++++++---------- app/Views/thz_notes.php | 120 ++++++++++++- 7 files changed, 350 insertions(+), 131 deletions(-) create mode 100644 app/Models/ThzHistoryModel.php rename app/Models/{TicketTypesModel.php => ThzTypeModel.php} (93%) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index acb156bd..42964439 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -562,6 +562,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("ticketList", "ThzController::ticketList"); $routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); $routes->get("ticketConversationList", "ThzController::ticketConversationList"); + $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); $routes->get("hrFileList", "EmployeeRestController::hrFileList"); $routes->get("hrFileUploadMasters", "EmployeeRestController::hrFileUploadMasters"); @@ -660,4 +661,5 @@ $routes->get("ticketList", "ThzController::ticketList"); $routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); $routes->get("ticketConversationList", "ThzController::ticketConversationList"); $routes->post('ticketAutoFetchDetails',"ThzController::ticketAutoFetchDetails"); -// $routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType'); \ No newline at end of file +$routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType'); +$routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); \ No newline at end of file diff --git a/app/Controllers/ThzController.php b/app/Controllers/ThzController.php index e286d651..fe6ad35b 100644 --- a/app/Controllers/ThzController.php +++ b/app/Controllers/ThzController.php @@ -8,12 +8,13 @@ use CodeIgniter\HTTP\ResponseInterface; use App\Models\ThzMasterModel; use App\Models\ThzMasterNotesModel; +use App\Models\ThzTypeModel; +use App\Models\ThzHistoryModel; use App\ControllerCleaners\ThzControllerCleaner; use App\Models\UserModel; use App\Models\ClientPolicyModel; use App\Models\ClientModel; use App\Models\TicketMailTemplateModel; -// use App\Models\TicketTypesModel; class ThzController extends BaseController @@ -21,7 +22,8 @@ class ThzController extends BaseController protected $thzMasterModel; protected $thzMasterNotesModel; - + protected $thzTypeModel; + protected $thzHistoryModel; protected $thzControllerCleaner; protected $userModel; @@ -29,16 +31,17 @@ class ThzController extends BaseController protected $clientModel; protected $ticketMailTemplateModel; - // protected $ticketTypesModel; public function __construct() { $this->thzMasterModel = new ThzMasterModel(); $this->thzMasterNotesModel = new ThzMasterNotesModel(); + $this->thzTypeModel = new thzTypeModel(); + $this->thzHistoryModel = new ThzHistoryModel(); $this->thzControllerCleaner = new ThzControllerCleaner(); $this->userModel = new UserModel(); $this->clientPolicyModel = new ClientPolicyModel(); - $this->clientModel = new ClientModel(); + $this->clientModel = new ClientModel(); $this->ticketMailTemplateModel = new TicketMailTemplateModel(); } @@ -55,6 +58,28 @@ class ThzController extends BaseController $text = "update"; $result = $this->updateTicket($data); + // here insert history Status. + $old = $this->thzMasterModel->where('thz_id', $data['thz_id'])->get()->getRowArray(); + + if ($old && isset($data['status'])) { + if ($old['status'] != $data['status']) { + $history = [ + 'thz_id' => $data['thz_id'], + 'field_name' => 'status', + 'display_name' => 'Status', + 'old_value' => $old['status'], + 'new_value' => $data['status'], + 'is_active' => 1 + ]; + + if (!empty(get_session_userid())) { + $history['created_by'] = get_session_userid(); + } + + $this->thzHistoryModel->insert($history); + } + } + $updateID = $data['thz_id']; } else { @@ -228,43 +253,63 @@ class ThzController extends BaseController } - // public function ticketType() - // { - // $method = $this->request->getMethod(); // get, post + public function ticketType() + { + $method = $this->request->getMethod(); // get, post - // if ($method === 'get') { + if ($method === 'get') { - // $types = $this->ticketTypesModel->where('is_active', 1)->findAll(); - // if (empty($types)) { - // return $this->response->setJSON(['status' => 'error','message' => 'No ticket types found'])->setStatusCode(404); - // } - // return $this->response->setJSON(['status' => 'success','data' => $types])->setStatusCode(200); + $types = $this->thzTypeModel->where('is_active', 1)->findAll(); + if (empty($types)) { + return $this->response->setJSON(['status' => 'error','message' => 'No ticket types found'])->setStatusCode(404); + } + return $this->response->setJSON(['status' => 'success','data' => $types])->setStatusCode(200); - // } + } - // if ($method === 'post') { + if ($method === 'post') { - // $data = $this->request->getPost(); - // if (!empty($data['id'])) { - // $text = "update"; - // $result = $this->ticketTypesModel->update($data['id'], $data); - // $updateID = $data['id']; - // } else { - // $text = "create"; - // $insertID = $this->ticketTypesModel->insert($data); - // $result = true; - // } + $data = $this->request->getPost(); + if (!empty($data['id'])) { + $text = "update"; + $result = $this->thzTypeModel->update($data['id'], $data); + $updateID = $data['id']; + } else { + $text = "create"; + $insertID = $this->thzTypeModel->insert($data); + $result = true; + } - // $id = isset($insertID) && !empty($insertID) ? $insertID : $updateID ; + $id = isset($insertID) && !empty($insertID) ? $insertID : $updateID ; - // return $this->response->setJSON([ - // 'status' => $id ? 'success' : 'error', - // 'message' => $id ? "Ticket Type {$text}d successfully " : "Unable to {$text} ticket type. Please try again." , - // 'id' => $id - // ])->setStatusCode($id ? 200 : 400); - // } - // return $this->response->setJSON(['status' => 'error','message' => 'No ticket types found'])->setStatusCode(404); - // } + return $this->response->setJSON([ + 'status' => $id ? 'success' : 'error', + 'message' => $id ? "Ticket Type {$text}d successfully " : "Unable to {$text} ticket type. Please try again." , + 'id' => $id + ])->setStatusCode($id ? 200 : 400); + } + return $this->response->setJSON(['status' => 'error','message' => 'No ticket types found'])->setStatusCode(404); + } + + public function ticketHistoryList() + { + + $data = $this->request->getGet(); + $thz_id = $data['thz_id']; + // $details = $this->thzHistoryModal->whereIn('thz_id', $thz_id)->where('is_active', 1)->get()->getResultArray(); + $details = $this->thzHistoryModel->select('thz_history.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as created_name') + ->join('user_profiles', 'user_profiles.id = thz_history.created_by', 'left') + ->where('thz_history.thz_id', $thz_id)->where('thz_history.is_active', 1)->get()->getResultArray(); + + + + if (empty($details)) { + return $this->response->setJSON([ 'status' => 'error','message' => 'No History found'])->setStatusCode(404); + } + + + return $this->response->setJSON(['status' => 'success','data' => $details])->setStatusCode(200); + } /************************************************** PRIVATE FUNCTIONS ********************************************************/ diff --git a/app/Models/ThzHistoryModel.php b/app/Models/ThzHistoryModel.php new file mode 100644 index 00000000..f7dd22d2 --- /dev/null +++ b/app/Models/ThzHistoryModel.php @@ -0,0 +1,45 @@ + diff --git a/app/Views/thz_list.php b/app/Views/thz_list.php index cde116e0..8b123006 100644 --- a/app/Views/thz_list.php +++ b/app/Views/thz_list.php @@ -7,52 +7,17 @@ width: 100%; } -/* HEADER */ -thead th { - background-color: #00999E; - color: #fff !important; - border-top: 0px solid #fff !important; - border-bottom: 0px solid #fff !important; -} - /* .table thead th { vertical-align: bottom; border-bottom: 2px solid #fff; } */ -/* Rounded header corners */ -thead th:first-child { - border-top-left-radius: 15px !important; - border-bottom-left-radius: 15px !important; -} -thead th:last-child { - border-top-right-radius: 15px !important; - border-bottom-right-radius: 15px !important; -} - -/* BODY ROWS */ -tbody td { - background: #F5FFFF; /* apply bg to td not tr */ - padding: 12px; - border-top: 1px solid #eee; - border-bottom: 1px solid #eee; -} /* Add shadow + spacing row "card" effect */ tbody tr { /* box-shadow: 0 2px 5px rgba(0,0,0,0.08); */ } -/* Rounded corners for first + last cell of each row */ -tbody tr td:first-child { - border-top-left-radius: 15px !important; - border-bottom-left-radius: 15px !important; -} -tbody tr td:last-child { - border-top-right-radius: 15px !important; - border-bottom-right-radius: 15px !important; -} - /* Hover effect */ #scroll-horizontal-datatable tbody tr:hover td { background-color: #e0e0e0; @@ -123,8 +88,7 @@ tbody tr td:last-child { white-space: nowrap !important; } */ - -.text-custom-black{ +.app-text-black{ color: #000000 !important; } .text-custom-grey{ @@ -251,8 +215,8 @@ table thead th {
- - +
+ @@ -265,7 +229,7 @@ table thead th { - + $row){ ?> @@ -394,9 +358,17 @@ table thead th { @@ -683,62 +655,66 @@ table thead th { document.getElementById('policy_id').value = policyId || ""; } - function hideandshowpolicy() { - var select = document.getElementById('ticket_type').value; - var policyContainer = document.getElementById('policy_container'); + // function hideandshowpolicy() { + // var select = document.getElementById('ticket_type').value; + // var policyContainer = document.getElementById('policy_container'); - if (select === 'Service') { - policyContainer.style.display = "block"; // show + // if (select === 'Service') { + // policyContainer.style.display = "block"; // show + // } else { + // policyContainer.style.display = "none"; // hide + // document.getElementById('policy_no').value = ""; + // document.getElementById('policy_id').value = ""; + // } + // } + +function hideandshowpolicy() { + var select = document.getElementById('ticket_type'); + var value = select.value; + var policyContainer = document.getElementById('policy_container'); + + if (value === "0") { + let newType = prompt("Enter new ticket type:"); + if (newType && newType.trim() !== "") { + + var formData = new FormData(form); + + $.ajax({ + url: "", + type: "POST", + data: formData, + processData: false, + contentType: false, + dataType: 'json', + success: function(response) { + if (response.status === "success") { + + let option = new Option(newType, newType); + let addNewOption = select.querySelector('option[value="0"]'); + select.insertBefore(option, addNewOption); + select.value = newType; + value = newType; + console.log(response.message); + + } else { console.log(response.message); value = ""; } + }, + error: function(xhr) { console.log("Error: " + xhr.statusText); value = ""; } + }); } else { - policyContainer.style.display = "none"; // hide - document.getElementById('policy_no').value = ""; - document.getElementById('policy_id').value = ""; + select.value = ""; + value = ""; } } -// function hideandshowpolicy() { -// var select = document.getElementById('ticket_type'); -// var value = select.value; -// var policyContainer = document.getElementById('policy_container'); + if (value === 'Service') { + policyContainer.style.display = "block"; + } else { + policyContainer.style.display = "none"; + document.getElementById('policy_no').value = ""; + document.getElementById('policy_id').value = ""; + } -// if (value === "0") { -// let newType = prompt("Enter new ticket type:"); -// if (newType && newType.trim() !== "") { - -// $.ajax({ -// url: "", -// type: "POST", -// data: { name: newType }, -// dataType: 'json', -// success: function(response) { -// if (response.status === "success") { - -// let option = new Option(newType, newType); -// let addNewOption = select.querySelector('option[value="0"]'); -// select.insertBefore(option, addNewOption); -// select.value = newType; -// value = newType; -// console.log(response.message); - -// } else { console.log(response.message); value = ""; } -// }, -// error: function(xhr) { console.log("Error: " + xhr.statusText); value = ""; } -// }); -// } else { -// select.value = ""; -// value = ""; -// } -// } - -// if (value === 'Service') { -// policyContainer.style.display = "block"; -// } else { -// policyContainer.style.display = "none"; -// document.getElementById('policy_no').value = ""; -// document.getElementById('policy_id').value = ""; -// } - -// } +} + \ No newline at end of file
Ticket ID NameUpdated At