Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
Gowtham M 2025-09-27 11:31:00 +05:30
commit a8875d4a48
5 changed files with 121 additions and 168 deletions

View File

@ -100,5 +100,7 @@ class Autoload extends AutoloadConfig
* @var string[]
* @phpstan-var list<string>
*/
public $helpers = ['uuid','session','utility', 'form', 'url', 'oauth', 'fileupload', 'excel_import_export', 'file', 'drive','ExcelSanitizeHelper', 'api_helper'];
public $helpers = ['uuid','session','utility', 'form', 'url', 'oauth', 'fileupload',
'excel_import_export', 'file', 'drive','ExcelSanitizeHelper', 'api_helper','ExceptionHelper'
];
}

View File

@ -69,30 +69,7 @@ class ThzController extends BaseController
$old = $this->thzMasterModel->where('thz_id', $data['thz_id'])->get()->getRowArray();
$result = $this->updateTicket($data);
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();
}
$hist_id = $this->thzHistoryModel->insert($history);
$references = $old['status'] . " - " . $data['status'] . " - " . $hist_id;
} else {
$references = $old['status'] . " - " . $data['status'];
}
} else {
$references = "No Details";
}
$references = ($old && isset($data['status'])) ? $this->handleTicketHistory($old, $data) : "No Details" ;
$updateID = $data['thz_id'];
} else {
@ -115,22 +92,10 @@ class ThzController extends BaseController
'notification' => $emailNotificationResult ? 'Email Notification Success..!!' : 'Email Notification Failed..!!',
'ref' => $references
])->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);
return handle_exception($e, $this->myLogger, $this->response);
}
}
@ -145,6 +110,11 @@ class ThzController extends BaseController
$data = $this->request->getGet();
if ($returnType === 'web' && in_array(get_role_id(), [3, 4])) {
$data['assign_to'] = $data['assign_to'] ?? get_session_userid();
}
$tickets = $this->fetchTicketsBasedOnrole($data);
@ -156,7 +126,7 @@ class ThzController extends BaseController
}
} else {
$data['ticket_data'] = $tickets;
$data['assignee'] = $this->userModel->where('is_active', 1)->whereIn('role', ['3', '4'])->findAll();
$data['assignee'] = $this->userModel->where('is_active', 1)->whereIn('role', ['3', '4'])->findAll();
// enga 5-"head" and 1-"admin" assign pannvaga so dropdown la varakudhathu , 2-"manager l2 " - ivangalum assign pannalam
// 3,4 remain person varannum.
$data['client_list'] = $this->clientModel->getCreatedByUserName();
@ -171,21 +141,7 @@ class ThzController extends BaseController
'data' => $tickets,
])->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);
return handle_exception($e, $this->myLogger, $this->response);
}
}
@ -204,35 +160,19 @@ class ThzController extends BaseController
throw new \RuntimeException('No tickets found', 404);
}
if ($data['notes_type'] == "External") {
$emailNotificationResult = $this->ticketConversationSaveNotification($data);
} else {
$emailNotificationResult = false;
}
$emailNotificationResult = ($data['notes_type'] === "External")
? $this->ticketConversationSaveNotification($data)
: false;
return $this->response->setJSON([
'status' => $result ? 'success' : 'error',
'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..!!'
])->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);
return handle_exception($e, $this->myLogger, $this->response);
}
}
@ -265,21 +205,7 @@ class ThzController extends BaseController
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);
return handle_exception($e, $this->myLogger, $this->response);
}
}
@ -295,7 +221,7 @@ class ThzController extends BaseController
if ($thz_id) {
$result['master'] = $this->thzMasterModel
->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name')
->select('thz_master.*, user_profiles.first_name as assignee_name')
->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left')
->where('thz_master.thz_id', $thz_id)
->findAll();
@ -304,7 +230,7 @@ class ThzController extends BaseController
$notes = $this->thzMasterNotesModel->ticketConversationList($thz_id, $returnType);
$result['notes'] = !empty($notes) ? $notes : [];
} else {
$this->myLogger->logme('error', 'No tickets found for ticket id ' . json_encode($thz_id));
$this->myLogger->logme('error', 'No tickets found for ticket id ' . json_encode($thz_id));
throw new \RuntimeException('No tickets found', 400);
}
} else {
@ -316,21 +242,7 @@ class ThzController extends BaseController
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);
return handle_exception($e, $this->myLogger, $this->response);
}
} else {
@ -342,7 +254,7 @@ class ThzController extends BaseController
: '';
$result['related_tickets'] = $this->thzMasterModel
->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name')
->select('thz_master.*, user_profiles.first_name as assignee_name')
->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left')
->where('thz_master.assign_to', $assign_to)
->where('thz_master.mobile', $mobile)
@ -368,7 +280,7 @@ class ThzController extends BaseController
if ($method === 'get') {
$types = $this->thzTypeModel->select('id,name,is_active')->where('is_active', 1)->findAll();
if (empty($types)) {
$this->myLogger->logme('error', 'No ticket types found ');
$this->myLogger->logme('error', 'No ticket types found ');
return $this->response->setJSON(['status' => 'error', 'message' => 'No ticket types found'])->setStatusCode(404);
}
return $this->response->setJSON(['status' => 'success', 'data' => $types])->setStatusCode(200);
@ -397,21 +309,7 @@ class ThzController extends BaseController
}
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);
return handle_exception($e, $this->myLogger, $this->response);
}
}
@ -421,7 +319,7 @@ class ThzController extends BaseController
$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')
$details = $this->thzHistoryModel->select('thz_history.*, user_profiles.first_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)
->orderBy('thz_history.created_at', 'desc')
@ -430,28 +328,14 @@ class ThzController extends BaseController
if (empty($details)) {
$this->myLogger->logme('error', 'No history details found for ticket id ' . json_encode($thz_id) );
$this->myLogger->logme('error', 'No history details found for ticket id ' . json_encode($thz_id));
throw new \RuntimeException('No History found', 404);
}
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);
return handle_exception($e, $this->myLogger, $this->response);
}
}
@ -629,23 +513,23 @@ class ThzController extends BaseController
$cc = getenv('G_ticketing_system_cc');
$this->myLogger->logme('error', "env for cc G_ticketing_system_cc ".$cc);
$this->myLogger->logme('error', "env for cc G_ticketing_system_cc " . $cc);
$template = empty($assignee_email)
? 'ticket_save_create_user_unassigned'
$template = empty($assignee_email)
? 'ticket_save_create_user_unassigned'
: 'ticket_save_create_user_assigned';
if (!empty($assignee_email)) {
$data['assignee_email'] = $assignee_email;
}
$this->sendEmail($template, $data, $user_email, $ticketId);
$this->sendEmail($template, $data, $user_email, $ticketId);
// send to account manager and if it is more than one email also no problem we send to all account managers
if (!empty($account_manager_email)) {
$this->myLogger->logme('error', "mail sent for account manager ". json_encode($account_manager_email));
$this->myLogger->logme('error', "mail sent for account manager " . json_encode($account_manager_email));
$this->sendEmail($template, $data, $account_manager_email, $ticketId, $cc);
}else{
} else {
$this->myLogger->logme('error', "mail not sent for account manager ");
}
@ -679,19 +563,19 @@ class ThzController extends BaseController
}
private function sendEmail($templateName, $data, $to_email, $ticketId , $cc = "", $bcc = "")
private function sendEmail($templateName, $data, $to_email, $ticketId, $cc = "", $bcc = "")
{
$mailTemplate = $this->ticketMailTemplateModel->where('template_name', $templateName)->findAll()[0] ?? [];
if (empty($mailTemplate)) {
$this->myLogger->logme('error','No Mail Template Found To send email in ticketing system');
$this->myLogger->logme('error', 'No Mail Template Found To send email in ticketing system');
return;
}
if( empty($cc)){
if (empty($cc)) {
$this->myLogger->logme('error', 'empty cc attached for template name : ' . json_encode($templateName));
}else{
} else {
$this->myLogger->logme('error', "cc attached for template name : " . json_encode($templateName));
}
@ -719,7 +603,6 @@ class ThzController extends BaseController
$res = MailHelper::send_email(['from_mail' => $from_mail, 'mail' => $to_mail, 'cc' => $cc_string, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to, 'bcc' => $bcc_string]);
$this->myLogger->logme('error', 'Mail Response : ' . json_encode($res));
}
@ -739,4 +622,34 @@ class ThzController extends BaseController
$data['policy_terms'] = $policy_terms;
return view('view_policy_terms', $data);
}
private function handleTicketHistory(array $old, array $data): string
{
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();
}
$hist_id = $this->thzHistoryModel->insert($history);
return $old['status'] . " - " . $data['status'] . " - " . $hist_id;
}
return $old['status'] . " - " . $data['status'];
}
}

View File

@ -0,0 +1,35 @@
<?php
// app/Helpers/ExceptionHelper.php
if (!function_exists('handle_exception')) {
function handle_exception(Throwable $e, $logger = null, $response = null)
{
$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()
];
if ($logger) {
$logger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0);
} else {
log_message('error', "Exception: {$context['message']} in {$context['file']} on line {$context['line']}");
}
return $response->setJSON([
'status' => 'error',
'message' => $isDbError ? 'Data Access Error' : $e->getMessage(),
'ref' => $isDbError ? 'database - ' : 'application - ' . $code . ' - ' . $e->getLine()
])->setStatusCode($code);
}
}

View File

@ -920,7 +920,8 @@ table.dataTable tbody td {
enableFiltering: false,
enableCaseInsensitiveFiltering: false,
includeSelectAllOption : false,
buttonWidth:'100%'
buttonWidth:'100%',
dropUp: true
});
$('.close').click(function(){

View File

@ -129,7 +129,7 @@
<div class="form-group col-md-4">
<label for="policy_no">Policy No<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Policy Number " name="policy_no" id="policy_no" required>
<input value="" type="text" class="form-control" oninput="checkPolicyNo(this)" placeholder="Enter Policy Number" name="policy_no" id="policy_no" required>
</div>
</div>
@ -1832,33 +1832,35 @@
}
$('#policy_no').change(function(){
//check dublicate policy number
function checkPolicyNo() {
var policy_no = $(this).val();
console.log(policy_no +'-'+policy_no.length);
var policy_no = $('#policy_no').val();
console.log(policy_no + '-' + policy_no.length);
policy_no = policy_no.trim();
console.log(policy_no +'-'+policy_no.length);
console.log(policy_no + '-' + policy_no.length);
$.ajax({
url: '<?php echo base_url('util/check_policy_no/');?>'+policy_no,
url: '<?php echo base_url('util/check_policy_no/');?>' + policy_no,
type: "GET",
dataType: 'json',
success: function (res) {
console.log(res);
if (res.status == true) {
console.log(res)
if(res.status == true){
toastr.warning(res.message, 'warning');
$('#policy_no').val('');
}else{
}
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
}
});
})
}
$(document).ready(function () {
// Check if the URL contains a hash