CHANGE TICKETING SYSTEM - VADIVEL J 2025-08-17

This commit is contained in:
vadivelJ96 2025-08-17 21:39:57 +05:30
parent 5133838a8b
commit d607afe5ed
2 changed files with 42 additions and 44 deletions

View File

@ -636,6 +636,6 @@ $routes->post('enrollment','VidalApiController::enrollment');
$routes->post("ticketSave", "ThzController::ticketSave"); $routes->post("ticketSave", "ThzController::ticketSave");
$routes->post("ticketList", "ThzController::ticketList"); $routes->get("ticketList", "ThzController::ticketList");
$routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); $routes->post("ticketConversationSave", "ThzController::ticketConversationSave");
$routes->post("ticketConversationList", "ThzController::ticketConversationList"); $routes->get("ticketConversationList", "ThzController::ticketConversationList");

View File

@ -8,6 +8,7 @@ use CodeIgniter\HTTP\ResponseInterface;
use App\Models\ThzMasterModel; use App\Models\ThzMasterModel;
use App\Models\ThzMasterNotesModel; use App\Models\ThzMasterNotesModel;
use App\ControllerCleaners\ThzControllerCleaner; use App\ControllerCleaners\ThzControllerCleaner;
use app\Models\UserModel;
class ThzController extends BaseController class ThzController extends BaseController
{ {
@ -17,11 +18,14 @@ class ThzController extends BaseController
protected $thzControllerCleaner; protected $thzControllerCleaner;
protected $userModel;
public function __construct() public function __construct()
{ {
$this->thzMasterModel = new ThzMasterModel(); $this->thzMasterModel = new ThzMasterModel();
$this->thzMasterNotesModel = new ThzMasterNotesModel(); $this->thzMasterNotesModel = new ThzMasterNotesModel();
$this->thzControllerCleaner = new ThzControllerCleaner(); $this->thzControllerCleaner = new ThzControllerCleaner();
$this->userModel = new UserModel();
} }
public function index() public function index()
@ -34,33 +38,25 @@ class ThzController extends BaseController
$data = $this->request->getJSON(true); $data = $this->request->getJSON(true);
if (!empty($data['thz_id'])) { if (!empty($data['thz_id'])) {
$data['updated_by'] = get_session_userid();
$ticket_id = $data['thz_id'];
$text = "update"; $text = "update";
$result = $this->updateTicket($data);
$result = $this->thzMasterModel->where('thz_id', $ticket_id)->set($data)->update();
} else { } else {
$data['created_by'] = get_session_userid();
$text = "create"; $text = "create";
$result = $this->insertTicket($data);
$result = $this->thzMasterModel->insert($data);
} }
return $this->response->setJSON(([ 'status' => $result ? 'success' : 'error' , return $this->response->setJSON([
'message' => $result ? "Ticket {$text}d successfully" : "Unable to {$text} ticket. Please try again." ])); 'status' => $result ? 'success' : 'error',
'message' => $result ? "Ticket {$text}d successfully" : "Unable to {$text} ticket. Please try again."
]);
} }
public function ticketList() public function ticketList()
{ {
$returnType = strtolower($this->request->getGet('return_type') ?? 'api'); $returnType = strtolower($this->request->getGet('return_type') ?? 'api');
$data = $this->request->getJSON(true); $data = $this->request->getGet();
$tickets = $this->fetchTicketsBasedOnrole($data); $tickets = $this->fetchTicketsBasedOnrole($data);
@ -86,16 +82,15 @@ class ThzController extends BaseController
]); ]);
} }
public function ticketConversationSave(){ public function ticketConversationSave(){
$data = $this->request->getJSON(true); $data = $this->request->getJSON(true);
$result = $this->thzMasterNotesModel->insert($data); $result = $this->thzMasterNotesModel->insert($data);
if(empty($result)){ if(empty($result)){
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found'])); return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']));
} }
return $this->response->setJSON((['status' => 'success', 'data' => $result])); return $this->response->setJSON((['status' => 'success', 'data' => $result]));
@ -104,40 +99,24 @@ class ThzController extends BaseController
public function ticketConversationList(){ public function ticketConversationList(){
$data = $this->request->getJSON(true); $data = $this->request->getGet();
$thz_id = $data['thz_id'] ?? null; $thz_id = $data['thz_id'] ?? null;
$result = $this->thzMasterNotesModel->ticketConversationList($thz_id); $result = $this->thzMasterNotesModel->ticketConversationList($thz_id);
if(empty($result)){ if(empty($result)){
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found'])); return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']));
} }
return $this->response->setJSON((['status' => 'success', 'data' => $result])); return $this->response->setJSON((['status' => 'success', 'data' => $result]));
} }
/************************************************** PRIVATE FUNCTIONS ********************************************************/ /************************************************** PRIVATE FUNCTIONS ********************************************************/
private function checkGeneralUserOrEmployee($data){
if($data['empcode']){
return $data['empcode'];
} elseif ($data['mobile']) {
return $data['mobile'];
} elseif ($data['email']) {
return $data['email'];
} else {
return null;
}
}
private function fetchTicketsBasedOnrole(array $data): array private function fetchTicketsBasedOnrole(array $data): array
{ {
$id = $data['thz_id'] ?? null; $id = $data['thz_id'] ?? null;
@ -163,6 +142,25 @@ class ThzController extends BaseController
return $this->thzMasterModel->findAll(); return $this->thzMasterModel->findAll();
} }
private function updateTicket($data){
$data['updated_by'] = get_session_userid();
$ticket_id = $data['thz_id'];
$result = $this->thzMasterModel->where('thz_id', $ticket_id)->set($data)->update();
return $result;
}
private function insertTicket($data){
$data['created_by'] = get_session_userid();
$result = $this->thzMasterModel->insert($data);
return $result;
}
} }