FIX_THZ Ticket Type

This commit is contained in:
venba-Inspriron-3558 2025-08-30 11:57:14 +05:30
parent 565905c874
commit 204a683284
4 changed files with 198 additions and 63 deletions

View File

@ -564,6 +564,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
$routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); $routes->post("ticketConversationSave", "ThzController::ticketConversationSave");
$routes->get("ticketConversationList", "ThzController::ticketConversationList"); $routes->get("ticketConversationList", "ThzController::ticketConversationList");
$routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); $routes->get("ticketHistoryList", "ThzController::ticketHistoryList");
$routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType');
$routes->get("hrFileList", "EmployeeRestController::hrFileList"); $routes->get("hrFileList", "EmployeeRestController::hrFileList");
$routes->get("hrFileUploadMasters", "EmployeeRestController::hrFileUploadMasters"); $routes->get("hrFileUploadMasters", "EmployeeRestController::hrFileUploadMasters");

View File

@ -31,6 +31,7 @@ class ThzController extends BaseController
protected $clientModel; protected $clientModel;
protected $ticketMailTemplateModel; protected $ticketMailTemplateModel;
protected $myLogger;
public function __construct() public function __construct()
{ {
@ -43,6 +44,7 @@ class ThzController extends BaseController
$this->clientPolicyModel = new ClientPolicyModel(); $this->clientPolicyModel = new ClientPolicyModel();
$this->clientModel = new ClientModel(); $this->clientModel = new ClientModel();
$this->ticketMailTemplateModel = new TicketMailTemplateModel(); $this->ticketMailTemplateModel = new TicketMailTemplateModel();
$this->myLogger = \Config\Services::mylogger();
} }
public function index() public function index()
@ -51,7 +53,8 @@ class ThzController extends BaseController
} }
public function ticketSave(){ public function ticketSave(){
try
{
$data = $this->request->getPost(); $data = $this->request->getPost();
if (!empty($data['thz_id'])) { if (!empty($data['thz_id'])) {
@ -99,11 +102,27 @@ class ThzController extends BaseController
'message' => $result ? "Ticket {$text}d successfully " : "Unable to {$text} ticket. Please try again." , 'message' => $result ? "Ticket {$text}d successfully " : "Unable to {$text} ticket. Please try again." ,
'notification' => $emailNotificationResult ? 'Email Notification Success..!!' : 'Email Notification Failed..!!' 'notification' => $emailNotificationResult ? 'Email Notification Success..!!' : 'Email Notification Failed..!!'
])->setStatusCode($result ? 200 : 400); ])->setStatusCode($result ? 200 : 400);
} catch (\Throwable $e) {
$code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;
$isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException
|| $e instanceof \mysqli_sql_exception
|| $e instanceof \PDOException;
$context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()];
$this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database' : 'application' . $code . ' / ' . $e->getLine()
])->setStatusCode($code);
}
} }
public function ticketList() public function ticketList()
{ {
try{
$returnType = strtolower($this->request->getGet('return_type') ?? 'api'); $returnType = strtolower($this->request->getGet('return_type') ?? 'api');
@ -117,7 +136,8 @@ class ThzController extends BaseController
if ($returnType === 'api') { if ($returnType === 'api') {
if (empty($tickets)) { if (empty($tickets)) {
return $this->response->setJSON([ 'status' => 'error','message' => 'No tickets found'])->setStatusCode(404); // return $this->response->setJSON([ 'status' => 'error','message' => 'No tickets found'])->setStatusCode(404);
throw new \RuntimeException('No tickets found', 400);
} }
}else{ }else{
@ -126,18 +146,37 @@ class ThzController extends BaseController
$data['assignee'] = $this->userModel->where('is_active', 1)->whereIn('role', ['2', '3','4'])->findAll(); // enga 5-"head" and 1-"admin" assign pannvaga so dropdown la varakudhathu $data['assignee'] = $this->userModel->where('is_active', 1)->whereIn('role', ['2', '3','4'])->findAll(); // enga 5-"head" and 1-"admin" assign pannvaga so dropdown la varakudhathu
// 2,3,4 remain person varannum. // 2,3,4 remain person varannum.
$data['client_list'] = $this->clientModel->getCreatedByUserName(); $data['client_list'] = $this->clientModel->getCreatedByUserName();
$data['ticket_type'] = $this->thzTypeModel->where('is_active', 1)->findAll();
return $this->loadLayout('thz_list', $data); return $this->loadLayout('thz_list', $data);
} }
return $this->response->setJSON([ return $this->response->setJSON([
'status' => 'success', 'status' => 'success',
'data' => $tickets, 'data' => $tickets,
])->setStatusCode(200); ])->setStatusCode(200);
}
catch (\Throwable $e) {
$code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;
$isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException
|| $e instanceof \mysqli_sql_exception
|| $e instanceof \PDOException;
$context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()];
$this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database' : 'application' . $code . ' / ' . $e->getLine()
])->setStatusCode($code);
}
} }
public function ticketConversationSave(){ public function ticketConversationSave(){
try {
$data = $this->request->getPost(); $data = $this->request->getPost();
$data['notes_type'] = $data['notes_type'] ?? 'External' ; $data['notes_type'] = $data['notes_type'] ?? 'External' ;
@ -145,7 +184,8 @@ class ThzController extends BaseController
$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']))->setStatusCode(404); // return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(404);
throw new \RuntimeException('No tickets found', 404);
} }
if($data['notes_type'] == "External"){ if($data['notes_type'] == "External"){
@ -161,41 +201,72 @@ class ThzController extends BaseController
'message' => $result ? "Ticket Notes created successfully" : "Unable to create ticket notes. Please try again." , 'message' => $result ? "Ticket Notes created successfully" : "Unable to create ticket notes. Please try again." ,
'notification' => $emailNotificationResult ? 'Email Notification Success..!!' : 'Email Notification Failed Or No Need..!!' 'notification' => $emailNotificationResult ? 'Email Notification Success..!!' : 'Email Notification Failed Or No Need..!!'
])->setStatusCode($result ? 200 : 400); ])->setStatusCode($result ? 200 : 400);
}
catch (\Throwable $e) {
$code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;
$isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException
|| $e instanceof \mysqli_sql_exception
|| $e instanceof \PDOException;
$context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()];
$this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database' : 'application' . $code . ' / ' . $e->getLine()
])->setStatusCode($code);
}
} }
public function ticketAutoFetchDetails(){ public function ticketAutoFetchDetails()
{
try {
$data = $this->request->getPost(); $data = $this->request->getPost();
$client_id = $data['client_id']; $client_id = $data['client_id'] ?? null;
$mobile = $data['mobile']; $mobile = $data['mobile'] ?? null;
if($client_id && $mobile){ if ($client_id && $mobile) {
$details = $this->thzMasterModel->ticketAutoFetchDetails($client_id, $mobile);
$details = $this->thzMasterModel->ticketAutoFetchDetails($client_id ,$mobile);
if(empty($details)){
return $this->response->setJSON((['status' => 'error', 'message' => 'No Data found']))->setStatusCode(400);
}else{
$policyIds = array_column($details, 'policy_id');
$policyIds = array_filter($policyIds);
$clientPolicy = $this->clientPolicyModel->whereIn('id', $policyIds)->where('is_active', 1)->get()->getResultArray();
$result['client_details'] = $details;
$result['policy_details'] = empty($clientPolicy) ? [] : $clientPolicy ;
if (empty($details)) {
throw new \RuntimeException('No Data found', 400);
} }
}else{
return $this->response->setJSON((['status' => 'error', 'message' => 'Client and Mobile Not found']))->setStatusCode(400); $policyIds = array_filter(array_column($details, 'policy_id'));
$clientPolicy = !empty($policyIds)
? $this->clientPolicyModel->whereIn('id', $policyIds)->where('is_active', 1)->get()->getResultArray()
: [];
$result['client_details'] = $details;
$result['policy_details'] = $clientPolicy ?? [];
} else {
throw new \RuntimeException('Client and Mobile Not found', 400);
} }
return $this->response->setJSON((['status' => 'success', 'data' => $result]))->setStatusCode(200); return $this->response->setJSON(['status' => 'success', 'data' => $result])->setStatusCode(200);
}
catch (\Throwable $e) {
$code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;
$isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException
|| $e instanceof \mysqli_sql_exception
|| $e instanceof \PDOException;
$context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()];
$this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database' : 'application' . $code . ' / ' . $e->getLine()
])->setStatusCode($code);
}
} }
public function ticketConversationList(){ public function ticketConversationList()
{
$data = $this->request->getGet(); $data = $this->request->getGet();
$returnType = strtolower($this->request->getGet('return_type') ?? 'api'); $returnType = strtolower($this->request->getGet('return_type') ?? 'api');
@ -215,16 +286,32 @@ class ThzController extends BaseController
$notes = $this->thzMasterNotesModel->ticketConversationList($thz_id, $returnType ); $notes = $this->thzMasterNotesModel->ticketConversationList($thz_id, $returnType );
$result['notes'] = !empty($notes) ? $notes : []; $result['notes'] = !empty($notes) ? $notes : [];
}else{ }else{
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(400); // return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(400);
throw new \RuntimeException('No tickets found', 400);
} }
}else{ }else{
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(404); // return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(404);
throw new \RuntimeException('No tickets found', 404);
} }
if ($returnType === 'api') { if ($returnType === 'api') {
return $this->response->setJSON((['status' => 'success', 'data' => $result]))->setStatusCode(200); try {
return $this->response->setJSON((['status' => 'success', 'data' => $result]))->setStatusCode(200);
} catch (\Throwable $e) {
$code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;
$isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException
|| $e instanceof \mysqli_sql_exception
|| $e instanceof \PDOException;
$context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()];
$this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database' : 'application' . $code . ' / ' . $e->getLine()
])->setStatusCode($code);
}
}else{ }else{
$assign_to = $result['master'][0]['assign_to']; $assign_to = $result['master'][0]['assign_to'];
@ -248,23 +335,23 @@ class ThzController extends BaseController
// 2,3,4 remain person varannum. // 2,3,4 remain person varannum.
$result['policy_terms'] = $toGetPolicyId ? $this->getPolicyTerms($toGetPolicyId) : ''; $result['policy_terms'] = $toGetPolicyId ? $this->getPolicyTerms($toGetPolicyId) : '';
return $this->loadLayout('thz_notes', $result); $result['ticket_type'] = $this->thzTypeModel->where('is_active', 1)->findAll();
}
return $this->loadLayout('thz_notes', $result);
}
} }
public function ticketType() public function ticketType()
{ {
$method = $this->request->getMethod(); // get, post $method = $this->request->getMethod(); // get, post
try{
if ($method === 'get') { if ($method === 'get') {
$types = $this->thzTypeModel->select('id,name,is_active')->where('is_active', 1)->findAll();
$types = $this->thzTypeModel->where('is_active', 1)->findAll();
if (empty($types)) { if (empty($types)) {
return $this->response->setJSON(['status' => 'error','message' => 'No ticket types found'])->setStatusCode(404); return $this->response->setJSON(['status' => 'error','message' => 'No ticket types found'])->setStatusCode(404);
} }
return $this->response->setJSON(['status' => 'success','data' => $types])->setStatusCode(200); return $this->response->setJSON(['status' => 'success','data' => $types])->setStatusCode(200);
} }
if ($method === 'post') { if ($method === 'post') {
@ -280,20 +367,37 @@ class ThzController extends BaseController
$result = true; $result = true;
} }
$id = isset($insertID) && !empty($insertID) ? $insertID : $updateID ; $id = isset($insertID) && !empty($insertID) ? $insertID : ($updateID ?? null);
return $this->response->setJSON([ return $this->response->setJSON([
'status' => $id ? 'success' : 'error', 'status' => $id ? 'success' : 'error',
'message' => $id ? "Ticket Type {$text}d successfully " : "Unable to {$text} ticket type. Please try again." , 'message' => $id ? "Ticket Type {$text}d successfully" : "Unable to {$text} ticket type. Please try again.",
'id' => $id 'id' => $id
])->setStatusCode($id ? 200 : 400); ])->setStatusCode($id ? 200 : 400);
} }
return $this->response->setJSON(['status' => 'error','message' => 'No ticket types found'])->setStatusCode(404); return $this->response->setJSON([ 'status' => 'error', 'message' => 'Invalid request method' ])->setStatusCode(405);
}
catch (\Throwable $e) {
$code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;
$isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException
|| $e instanceof \mysqli_sql_exception
|| $e instanceof \PDOException;
$context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()];
$this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database' : 'application' . $code . ' / ' . $e->getLine()
])->setStatusCode($code);
}
} }
public function ticketHistoryList() public function ticketHistoryList()
{ {
try
{
$data = $this->request->getGet(); $data = $this->request->getGet();
$thz_id = $data['thz_id']; $thz_id = $data['thz_id'];
// $details = $this->thzHistoryModal->whereIn('thz_id', $thz_id)->where('is_active', 1)->get()->getResultArray(); // $details = $this->thzHistoryModal->whereIn('thz_id', $thz_id)->where('is_active', 1)->get()->getResultArray();
@ -306,11 +410,27 @@ class ThzController extends BaseController
if (empty($details)) { if (empty($details)) {
return $this->response->setJSON([ 'status' => 'error','message' => 'No History found'])->setStatusCode(404); // return $this->response->setJSON([ 'status' => 'error','message' => 'No History found'])->setStatusCode(404);
throw new \RuntimeException('No History found', 404);
} }
return $this->response->setJSON(['status' => 'success','data' => $details])->setStatusCode(200); return $this->response->setJSON(['status' => 'success','data' => $details])->setStatusCode(200);
} catch (\Throwable $e) {
$code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500;
$isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException
|| $e instanceof \mysqli_sql_exception
|| $e instanceof \PDOException;
$context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()];
$this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database / ' : 'application / ' . $code . ' / ' . $e->getLine()
])->setStatusCode($code);
}
} }

View File

@ -7,8 +7,17 @@
width: 100%; width: 100%;
} }
/* .table thead th {
vertical-align: bottom;
border-bottom: 2px solid #fff;
} */
/* Add shadow + spacing row "card" effect */
tbody tr {
/* box-shadow: 0 2px 5px rgba(0,0,0,0.08); */
}
/* Search input with icon */ /* Search input with icon */
.dataTables_filter { .dataTables_filter {
position: absolute; position: absolute;
@ -196,7 +205,7 @@ table thead th {
</div> </div>
</div> </div>
<div> <div>
<table data-custom-table-css="table" id="scroll-horizontal-datatable" class="table w-100 nowrap text-custom-black text-custom app-font-family app-datatable"> <table id="scroll-horizontal-datatable" class="table w-100 nowrap text-custom-black text-custom app-font-family app-datatable">
<thead class="app-table-head"> <thead class="app-table-head">
<tr> <tr>
<th>Ticket ID</th> <th>Ticket ID</th>
@ -341,17 +350,17 @@ table thead th {
<label for="ticket_type">Ticket Type<span class="text-danger">*</span></label> <label for="ticket_type">Ticket Type<span class="text-danger">*</span></label>
<select class="form-control" id="ticket_type" name="ticket_type" required onchange="hideandshowpolicy()"> <select class="form-control" id="ticket_type" name="ticket_type" required onchange="hideandshowpolicy()">
<option value="">Select Ticket Type</option> <option value="">Select Ticket Type</option>
<option value="Sales" selected >Sales</option> <!-- <option value="Sales" selected >Sales</option> -->
<option value="Service">Service</option> <!-- <option value="Service">Service</option> -->
<!-- <option value="0">+ Add New</option> <!-- <option value="0">+ Add New</option> -->
<?php if (!empty($ticket_type)): ?> <?php if (!empty($ticket_type)): ?>
<?php foreach ($ticket_type as $t): ?> <?php foreach ($ticket_type as $t): ?>
<option value="<?= esc($t['name']) ?>" <option value="<?= esc($t['name']) ?>"
<?= ($t['name'] === "Sales") ? 'selected' : '' ?>> <?= (strtolower($t['name']) === "sales") ? 'selected' : '' ?>>
<?= esc($t['name']) ?> <?= esc($t['name']) ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?> --> <?php endif; ?>
</select> </select>
</div> </div>
@ -725,15 +734,14 @@ $(document).ready(function() {
hideandshowpolicy(); hideandshowpolicy();
var ticketsTable = $('#scroll-horizontal-datatable'); var ticketsTable = $('#scroll-horizontal-datatable');
$('#scroll-horizontal-datatable_filter').prepend('<i class="mdi mdi-magnify"></i>');
if (ticketsTable.length) { if (ticketsTable.length) {
ticketsTable.DataTable({ ticketsTable.DataTable({
scrollX: true, scrollX: true,
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + dom: "<'row'<'col-sm-2'f><'col-sm-10 text-right'B>>" +
"<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>", "<'row'<'col-sm-5'i><'col-sm-7'p>>",
buttons: [ buttons: [
{ {
text: '<i class="mdi mdi-plus" ></i><span class="app-font-family btn-custom"> Create New Ticket </span>', text: '<i class="mdi mdi-plus" ></i><span class="app-font-family btn-custom"> Create New Ticket </span>',
@ -775,7 +783,6 @@ $(document).ready(function() {
}, },
paging: true, paging: true,
pageLength: 25, pageLength: 25,
ordering: false,
}); });
} else { } else {

View File

@ -347,8 +347,15 @@ hr{
<label for="ticket_type" class="sub-title-text app-font-family">Ticket Type<span class="text-danger">*</span></label> <label for="ticket_type" class="sub-title-text app-font-family">Ticket Type<span class="text-danger">*</span></label>
<select class="form-control" id="ticket_type" name="ticket_type" required> <select class="form-control" id="ticket_type" name="ticket_type" required>
<option value="">Select Ticket Type</option> <option value="">Select Ticket Type</option>
<option value="Sales">Sales</option> <!-- <option value="Sales">Sales</option>
<option value="Service">Service</option> <option value="Service">Service</option> -->
<?php if (!empty($ticket_type)): ?>
<?php foreach ($ticket_type as $t): ?>
<option value="<?= esc($t['name']) ?>" >
<?= esc($t['name']) ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select> </select>
</div> </div>