Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
322fabd1c5
@ -1538,7 +1538,7 @@ class ClientController extends AdminController
|
||||
|
||||
|
||||
|
||||
|
||||
// Save Rack Rate function
|
||||
public function createClientPolicyPremium()
|
||||
{
|
||||
|
||||
|
||||
@ -1193,9 +1193,6 @@ class PolicyTransactionController extends BaseController
|
||||
// $data['is_cd_reduce_from_bds'] = 1;
|
||||
// }
|
||||
|
||||
$data['is_cd_reduce_from_bds'] = ($data['policy_type_id'] > 7 && $data['client_type'] == 1) ? 1 : 0;
|
||||
|
||||
|
||||
if (empty($data['data_received_date'])) {
|
||||
$data['data_received_date'] = null;
|
||||
} else {
|
||||
@ -1255,6 +1252,8 @@ class PolicyTransactionController extends BaseController
|
||||
$client_branch_id = $issue_type['client_branch_id'];
|
||||
}
|
||||
|
||||
$data['is_cd_reduce_from_bds'] = (isset($issue_type['policy_type_id']) && $issue_type['policy_type_id'] > 7 && $data['client_type'] == 1) ? 1 : 0;
|
||||
|
||||
// if($data['bro_payable_by'] == ""){
|
||||
// $data['bro_payable_by'] = $issue_type['bro_payable_by'];
|
||||
// }
|
||||
@ -1324,13 +1323,16 @@ class PolicyTransactionController extends BaseController
|
||||
}
|
||||
|
||||
private function updateEndorsementTransaction($id, $data)
|
||||
{
|
||||
{
|
||||
$old_endorse_data = $this->policyTransactionModel->where('id', $id)->where('is_active', 1)->first();
|
||||
$update = $this->policyTransactionModel->where('id', $id)->set($data)->update();
|
||||
|
||||
if ($update) {
|
||||
|
||||
$this->insertTransactionStatus($id, $data, 1);
|
||||
$this->handleCompletedStatus($data, $id);
|
||||
if($old_endorse_data['status'] != "completed"){
|
||||
$this->handleCompletedStatus($data, $id);
|
||||
}
|
||||
$this->insertOrUpdateCoShareDetails($data, $id);
|
||||
|
||||
|
||||
@ -1344,11 +1346,10 @@ class PolicyTransactionController extends BaseController
|
||||
{
|
||||
if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) {
|
||||
|
||||
$tolamt = $data['total'][0] ?? 0;
|
||||
$tolamt = (int) $data['total'][0] ?? 0;
|
||||
|
||||
$description = 'The following amount of Rs. ' . round($tolamt, 2) . '/- has been' .
|
||||
($data['action_type'] == 'deletion' ? ' Credit ' : ' Debit ') . 'from the policy transaction (BDS)';
|
||||
|
||||
$cd_tranction_data = [
|
||||
'amount' => $tolamt,
|
||||
'sub_type_id' => $data['action_type'] == 'deletion' ? 3 : 4,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
723
app/Controllers/ThzController_old.php
Normal file
723
app/Controllers/ThzController_old.php
Normal file
@ -0,0 +1,723 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Helpers\MailHelper;
|
||||
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\ClientRMModel;
|
||||
|
||||
|
||||
class ThzController extends BaseController
|
||||
{
|
||||
|
||||
protected $thzMasterModel;
|
||||
protected $thzMasterNotesModel;
|
||||
protected $thzTypeModel;
|
||||
protected $thzHistoryModel;
|
||||
protected $thzControllerCleaner;
|
||||
|
||||
protected $userModel;
|
||||
protected $clientPolicyModel;
|
||||
protected $clientModel;
|
||||
|
||||
protected $ticketMailTemplateModel;
|
||||
|
||||
protected $cientRmModel;
|
||||
protected $myLogger;
|
||||
|
||||
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->cientRmModel = new ClientRMModel();
|
||||
$this->ticketMailTemplateModel = new TicketMailTemplateModel();
|
||||
$this->myLogger = \Config\Services::mylogger();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function ticketSave()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
$references = "";
|
||||
if (!empty($data['thz_id'])) {
|
||||
|
||||
$text = "update";
|
||||
// here insert history Status.
|
||||
$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";
|
||||
}
|
||||
|
||||
$updateID = $data['thz_id'];
|
||||
} else {
|
||||
|
||||
$text = "create";
|
||||
$insertID = $this->insertTicket($data);
|
||||
$result = true;
|
||||
$references = "";
|
||||
}
|
||||
|
||||
$id = isset($insertID) && !empty($insertID) ? $insertID : $updateID;
|
||||
|
||||
$emailNotificationResult = $this->ticketSaveNotification($data, $insertOrUpdate = $text, $id);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => $result ? 'success' : 'error',
|
||||
'message' => $result ? "Ticket {$text}d successfully " : "Unable to {$text} ticket. Please try again.",
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
||||
public function ticketList()
|
||||
{
|
||||
|
||||
try {
|
||||
$returnType = strtolower($this->request->getGet('return_type') ?? 'api');
|
||||
|
||||
|
||||
$data = $this->request->getGet();
|
||||
if ($returnType === 'web' && in_array(get_role_id(), [2, 3, 4])) {
|
||||
$data['assign_to'] = $data['assign_to'] ?? get_session_userid();
|
||||
}
|
||||
|
||||
$tickets = $this->fetchTicketsBasedOnrole($data);
|
||||
|
||||
|
||||
if ($returnType === 'api') {
|
||||
if (empty($tickets)) {
|
||||
// return $this->response->setJSON([ 'status' => 'error','message' => 'No tickets found'])->setStatusCode(404);
|
||||
throw new \RuntimeException('No tickets found', 400);
|
||||
}
|
||||
} else {
|
||||
|
||||
$data['page_name'] = "Tickets";
|
||||
$data['ticket_data'] = $tickets;
|
||||
$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.
|
||||
$data['client_list'] = $this->clientModel->getCreatedByUserName();
|
||||
$data['ticket_type'] = $this->thzTypeModel->where('is_active', 1)->findAll();
|
||||
|
||||
return $this->loadLayout('thz_list', $data);
|
||||
}
|
||||
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
||||
public function ticketConversationSave()
|
||||
{
|
||||
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$data['notes_type'] = $data['notes_type'] ?? 'External';
|
||||
|
||||
$result = $this->thzMasterNotesModel->insert($data);
|
||||
|
||||
if (empty($result)) {
|
||||
// return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(404);
|
||||
throw new \RuntimeException('No tickets found', 404);
|
||||
}
|
||||
|
||||
if ($data['notes_type'] == "External") {
|
||||
$emailNotificationResult = $this->ticketConversationSaveNotification($data);
|
||||
} else {
|
||||
$emailNotificationResult = 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);
|
||||
}
|
||||
}
|
||||
|
||||
public function ticketAutoFetchDetails()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$client_id = $data['client_id'] ?? null;
|
||||
$mobile = $data['mobile'] ?? null;
|
||||
|
||||
if ($client_id && $mobile) {
|
||||
$details = $this->thzMasterModel->ticketAutoFetchDetails($client_id, $mobile);
|
||||
|
||||
if (empty($details)) {
|
||||
throw new \RuntimeException('No Data found', 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);
|
||||
} 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()
|
||||
{
|
||||
$data = $this->request->getGet();
|
||||
|
||||
$returnType = strtolower($this->request->getGet('return_type') ?? 'api');
|
||||
|
||||
$thz_id = $data['thz_id'] ?? null;
|
||||
|
||||
$ticketType = $data['notes_type'] ?? 'External';
|
||||
|
||||
if ($thz_id) {
|
||||
$result['master'] = $this->thzMasterModel
|
||||
->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name')
|
||||
->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left')
|
||||
->where('thz_master.thz_id', $thz_id)
|
||||
->findAll();
|
||||
|
||||
if (!empty($result['master'])) {
|
||||
$notes = $this->thzMasterNotesModel->ticketConversationList($thz_id, $returnType);
|
||||
$result['notes'] = !empty($notes) ? $notes : [];
|
||||
} else {
|
||||
// return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(400);
|
||||
throw new \RuntimeException('No tickets found', 400);
|
||||
}
|
||||
} else {
|
||||
// return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(404);
|
||||
throw new \RuntimeException('No tickets found', 404);
|
||||
}
|
||||
|
||||
if ($returnType === 'api') {
|
||||
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 {
|
||||
|
||||
$assign_to = $result['master'][0]['assign_to'];
|
||||
$mobile = $result['master'][0]['mobile'];
|
||||
|
||||
$toGetPolicyId = (!empty($result['master'][0]['policy_id']) && strtolower($result['master'][0]['policy_id']) !== 'null')
|
||||
? $result['master'][0]['policy_id']
|
||||
: '';
|
||||
|
||||
$result['related_tickets'] = $this->thzMasterModel
|
||||
->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_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)
|
||||
->where('thz_master.thz_id !=', $thz_id)
|
||||
->where('thz_master.status !=', 'Closed')
|
||||
->where('thz_master.status !=', 'Resolved')
|
||||
->findAll();
|
||||
|
||||
$result['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.
|
||||
$result['policy_terms'] = $toGetPolicyId ? $this->getPolicyTerms($toGetPolicyId) : '';
|
||||
|
||||
$result['ticket_type'] = $this->thzTypeModel->where('is_active', 1)->findAll();
|
||||
|
||||
return $this->loadLayout('thz_notes', $result);
|
||||
}
|
||||
}
|
||||
|
||||
public function ticketType()
|
||||
{
|
||||
$method = $this->request->getMethod(); // get, post
|
||||
try {
|
||||
if ($method === 'get') {
|
||||
$types = $this->thzTypeModel->select('id,name,is_active')->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') {
|
||||
|
||||
$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 ?? null);
|
||||
|
||||
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' => '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()
|
||||
{
|
||||
try {
|
||||
$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)
|
||||
->orderBy('thz_history.created_at', 'desc')
|
||||
->get()->getResultArray();
|
||||
|
||||
|
||||
|
||||
if (empty($details)) {
|
||||
// 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);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************************** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
|
||||
private function fetchTicketsBasedOnrole(array $data): array
|
||||
{
|
||||
// $id = $data['thz_id'] ?? null;
|
||||
$assign_to = $data['assign_to'] ?? null;
|
||||
$mobile = $data['mobile'] ?? null;
|
||||
|
||||
if (!empty($assign_to)) {
|
||||
// Tickets assigned to a staff
|
||||
return $this->thzMasterModel
|
||||
->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name')
|
||||
->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left')
|
||||
->where('thz_master.assign_to', $assign_to)
|
||||
->orderBy('thz_master.created_at', 'desc')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
// if (!empty($id) && !empty($mobile)) {
|
||||
if (!empty($mobile)) {
|
||||
// Specific ticket by ID and mobile
|
||||
return $this->thzMasterModel
|
||||
->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name')
|
||||
->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left')
|
||||
// ->where('thz_id', $id)
|
||||
->where('thz_master.mobile', $mobile)
|
||||
->orderBy('thz_master.created_at', 'desc')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
// All tickets (e.g., for managers)
|
||||
return $this->thzMasterModel
|
||||
->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name')
|
||||
->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left')
|
||||
->orderBy('thz_master.created_at', 'desc')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function ticketSaveNotification($data, $insertOrUpdate, $id)
|
||||
{
|
||||
|
||||
$user_email = $data['email'] ?? null;
|
||||
|
||||
$assignee_id = $data['assign_to'] ?? null;
|
||||
|
||||
$assignee_email = $this->findAssigneeEmail($assignee_id);
|
||||
|
||||
$client_id = $data['client_id'] ?? null;
|
||||
|
||||
$emailToNotified = [
|
||||
'user_email' => $user_email,
|
||||
'assignee_email' => $assignee_email
|
||||
];
|
||||
|
||||
$ticketId = $id;
|
||||
|
||||
$result = $this->ticketSaveEmailNotificationBasedOnRole($emailToNotified, $insertOrUpdate, $ticketId, $data, $client_id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function ticketConversationSaveNotification($data)
|
||||
{
|
||||
|
||||
$thz_id = $data['thz_id']; // thz is alias of ticket
|
||||
|
||||
$data['subject'] = $this->findSubject($data['thz_id']);
|
||||
|
||||
$assignee_id = $this->findAssigneeId($data['thz_id']);
|
||||
|
||||
$user_email = $this->findUserEmail($data['thz_id']);
|
||||
|
||||
$assignee_email = $this->findAssigneeEmail($assignee_id) ?? '';
|
||||
|
||||
$sender_mail = $data['notes_by'] == "User" ? $user_email : $assignee_email;
|
||||
$receiver_mail = $data['notes_by'] == "User" ? $assignee_email : $user_email;
|
||||
|
||||
$templateName = "ticket_conversation_save_notification";
|
||||
|
||||
$to_email = $receiver_mail;
|
||||
|
||||
$ticketId = $thz_id;
|
||||
|
||||
$message = $data['notes'] ?? '';
|
||||
|
||||
$this->sendEmail($templateName, $data, $to_email, $ticketId, $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function findAssigneeEmail($assignee_id)
|
||||
{
|
||||
|
||||
$row = $this->userModel->where('id', $assignee_id)->get()->getRow();
|
||||
$assigneeEmail = $row ? $row->email : null;
|
||||
return $assigneeEmail ? $assigneeEmail : "";
|
||||
}
|
||||
|
||||
private function findAssigneeId($ticketId)
|
||||
{
|
||||
$row = $this->thzMasterModel->where('thz_id', $ticketId)->get()->getRow();
|
||||
$assigneeId = $row ? $row->assign_to : null;
|
||||
return $assigneeId ? $assigneeId : 0;
|
||||
}
|
||||
|
||||
private function findUserEmail($ticket_id)
|
||||
{
|
||||
$row = $this->thzMasterModel->where('thz_id', $ticket_id)->get()->getRow();
|
||||
$email = $row ? $row->email : null;
|
||||
return $email ? $email : " ";
|
||||
}
|
||||
|
||||
private function findSubject($ticketId)
|
||||
{
|
||||
$row = $this->thzMasterModel->where('thz_id', $ticketId)->get()->getRow();
|
||||
$subject = $row ? $row->subject : null;
|
||||
return $subject ? $subject : " ";
|
||||
}
|
||||
|
||||
private function ticketSaveEmailNotificationBasedOnRole($emailToNotified, $insertOrUpdate, $ticketId, $data, $client_id)
|
||||
{
|
||||
|
||||
$user_email = $emailToNotified['user_email'] ?? null;
|
||||
$assignee_email = $emailToNotified['assignee_email'] ?? null;
|
||||
|
||||
|
||||
if (!empty($assignee_email)) {
|
||||
|
||||
switch ($insertOrUpdate) {
|
||||
|
||||
case 'update':
|
||||
|
||||
$this->sendEmail('ticket_save_update_assignee', $data, $assignee_email, $ticketId);
|
||||
|
||||
break;
|
||||
|
||||
case 'create':
|
||||
|
||||
$this->sendEmail('ticket_save_create_assignee', $data, $assignee_email, $ticketId);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($user_email)) {
|
||||
|
||||
switch ($insertOrUpdate) {
|
||||
|
||||
case 'update':
|
||||
|
||||
$data['assigneeAndStatus'] = empty($assignee_email)
|
||||
? "Not Yet Assigned"
|
||||
: "Assigned With {$assignee_email}";
|
||||
|
||||
$this->sendEmail('ticket_save_update_user', $data, $user_email, $ticketId);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'create':
|
||||
|
||||
$account_manager_email = $this->cientRmModel->findAccountManagerEmail($client_id);
|
||||
|
||||
$cc = getenv(' G_ticketing_system_cc');
|
||||
|
||||
$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);
|
||||
|
||||
// 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->sendEmail($template, $data, $account_manager_email, $ticketId, $cc);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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();
|
||||
$this->thzMasterModel->insert($data);
|
||||
|
||||
return $this->thzMasterModel->insertID(); // returns the inserted row's ID
|
||||
}
|
||||
|
||||
|
||||
private function sendEmail($templateName, $data, $to_email, $ticketId , $cc = "", $message = "", $bcc = "")
|
||||
{
|
||||
|
||||
$mailTemplate = $this->ticketMailTemplateModel->where('template_name', $templateName)->findAll()[0] ?? [];
|
||||
|
||||
if (empty($mailTemplate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mailTemplate['subject'] = str_replace('%subject%', $data['subject'] ?? '', $mailTemplate['subject']);
|
||||
|
||||
$mailTemplate['mail_content'] = str_replace('%subject%', $data['subject'] ?? '', $mailTemplate['mail_content']);
|
||||
|
||||
$mailTemplate['mail_content'] = str_replace('%ticketId%', $ticketId ?? '', $mailTemplate['mail_content']);
|
||||
|
||||
$mailTemplate['mail_content'] = str_replace('%message%', $message ?? '', $mailTemplate['mail_content']);
|
||||
|
||||
$mailTemplate['mail_content'] = str_replace('%assignee_email%', $data['assignee_email'] ?? '', $mailTemplate['mail_content']);
|
||||
|
||||
$mailTemplate['mail_content'] = str_replace('%assigneeAndStatus%', $data['assigneeAndStatus'] ?? '', $mailTemplate['mail_content']);
|
||||
|
||||
$from_mail = "";
|
||||
$to_mail = $to_email;
|
||||
$cc_string = $cc;
|
||||
$subject = $mailTemplate['subject'];
|
||||
$message = $mailTemplate['mail_content'];
|
||||
$attachments = "";
|
||||
$reply_to = "";
|
||||
$bcc_string = $bcc;
|
||||
|
||||
$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]);
|
||||
}
|
||||
|
||||
|
||||
public function getPolicyTerms($client_policy_id)
|
||||
{
|
||||
$policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $client_policy_id)->first();
|
||||
|
||||
$policy_terms = [];
|
||||
if (isset($policy_data['policy_terms']) && !empty($policy_data['policy_terms'])) {
|
||||
|
||||
$raw_terms = json_decode($policy_data['policy_terms'] ?? [], true) ?? [];
|
||||
|
||||
$ticketController = new TicketController();
|
||||
$policy_terms = $ticketController->convertTermsToDisplay($raw_terms);
|
||||
}
|
||||
|
||||
$data['policy_terms'] = $policy_terms;
|
||||
return view('view_policy_terms', $data);
|
||||
}
|
||||
}
|
||||
@ -882,6 +882,7 @@ if (isset($selected_lead_type)) {
|
||||
if (data.salse_person_id) {
|
||||
selecSalsePerson(data.salse_person_id);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error in dynamicLeadsDataForEdit function:', error);
|
||||
$('.loader').fadeOut();
|
||||
@ -1147,6 +1148,22 @@ if (isset($selected_lead_type)) {
|
||||
dateFormat: "d-m-Y"
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
let selectedOption = $('#contact_person_summary option').filter(function () {
|
||||
return $(this).text().trim() === (data.contact_person_name || '').trim();
|
||||
});
|
||||
|
||||
if (selectedOption.length) {
|
||||
selectedOption.prop('selected', true);
|
||||
console.log("Selected option:", selectedOption.text().trim(), "Value:", selectedOption.val());
|
||||
} else {
|
||||
console.log("No match found for:", data.contact_person_name);
|
||||
}
|
||||
|
||||
$('#contact_person_summary').trigger('change');
|
||||
}, 2000);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -3464,6 +3464,11 @@ function appendNewTab(tabNameData = null, data = null)
|
||||
}
|
||||
}
|
||||
|
||||
$('.nav-link').click(function(){
|
||||
$('.nav-link').removeClass('active-tab');
|
||||
$(this).addClass('active-tab');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function appendGridData(data, policy_grid_id_value = null, unique_id = null)
|
||||
|
||||
@ -363,11 +363,11 @@
|
||||
<td>Is Leader?</td>
|
||||
</tr>
|
||||
|
||||
<tr id="table_tr_33">
|
||||
<tr id="table_tr_34">
|
||||
<td>CD Acc No</td>
|
||||
</tr>
|
||||
|
||||
<tr id="table_tr_34">
|
||||
<tr id="table_tr_37">
|
||||
<td>CD Amount</td>
|
||||
</tr>
|
||||
|
||||
@ -602,20 +602,32 @@ $(document).ready(function(){
|
||||
var end_date = $(this).find('option:selected').attr('data-ed');
|
||||
var policy_type_id = $(this).find('option:selected').attr('data-ptid');
|
||||
|
||||
if(policy_type_id == 1 || policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5 || policy_type_id == 6 || policy_type_id == 7){
|
||||
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false)
|
||||
}else{
|
||||
$('#is_cd_reduce_from_bds').prop('disabled',false)
|
||||
}
|
||||
// if(policy_type_id == 1 || policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5 || policy_type_id == 6 || policy_type_id == 7){
|
||||
// $('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false)
|
||||
// }else{
|
||||
// $('#is_cd_reduce_from_bds').prop('disabled',false)
|
||||
// }
|
||||
|
||||
if( policy_type_id > 7 ){
|
||||
$('#tpa_endorse_div').hide();
|
||||
$('#no_of_insured_endorse_div').hide();
|
||||
$('#no_of_dependents_endorse_div').hide();
|
||||
$('#table_tr_34').show();
|
||||
$('#table_tr_37').show();
|
||||
}else{
|
||||
$('#tpa_endorse_div').show();
|
||||
$('#table_tr_34').hide();
|
||||
$('#table_tr_37').hide();
|
||||
}
|
||||
|
||||
|
||||
if(policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5){
|
||||
$('#no_of_insured_endorse_div').show();
|
||||
$('#no_of_dependents_endorse_div').show();
|
||||
}else if(policy_type_id == 1 || policy_type_id == 6 || policy_type_id == 7) {
|
||||
$('#no_of_insured_endorse_div').show();
|
||||
$('#no_of_dependents_endorse_div').hide();
|
||||
}else{
|
||||
$('#no_of_insured_endorse_div').hide();
|
||||
$('#no_of_dependents_endorse_div').hide();
|
||||
}
|
||||
|
||||
|
||||
@ -822,8 +834,13 @@ $('#client_type').on('change', function() {
|
||||
|
||||
if (selectedClientType == 2) {
|
||||
$('.branchdiv').hide();
|
||||
$('#table_tr_34').hide();
|
||||
$('#table_tr_37').hide();
|
||||
} else {
|
||||
$('.branchdiv').show();
|
||||
$('#table_tr_34').show();
|
||||
$('#table_tr_37').show();
|
||||
|
||||
}
|
||||
|
||||
console.log('selectedClientType', selectedClientType);
|
||||
@ -850,8 +867,14 @@ $('#client_type').on('change', function() {
|
||||
|
||||
}
|
||||
|
||||
$('#client_policy_id').empty().append($('<option>', {
|
||||
value: '',
|
||||
text: 'Select Policy'
|
||||
}))
|
||||
|
||||
// Initialize or refresh Select2 for both dropdowns
|
||||
$('#client_id').select2();
|
||||
$('#client_policy_id').select2();
|
||||
});
|
||||
|
||||
$('#endorsement_no').on('change', function(){
|
||||
@ -968,11 +991,11 @@ function getPolicyTransactionDataForEndorsementEdit(input){
|
||||
$('#policy_with_corr').prop('checked', false);
|
||||
}
|
||||
|
||||
if (res.data.is_cd_reduce_from_bds == 1) {
|
||||
$('#is_cd_reduce_from_bds').prop('checked', true).prop('checked', false);
|
||||
} else {
|
||||
$('#is_cd_reduce_from_bds').prop('checked', false);
|
||||
}
|
||||
// if (res.data.is_cd_reduce_from_bds == 1) {
|
||||
// $('#is_cd_reduce_from_bds').prop('checked', true).prop('checked', false);
|
||||
// } else {
|
||||
// $('#is_cd_reduce_from_bds').prop('checked', false);
|
||||
// }
|
||||
|
||||
if (res.data.action_type == 'policy_instalment') {
|
||||
$('.install_due_date_div').show()
|
||||
@ -990,11 +1013,11 @@ function getPolicyTransactionDataForEndorsementEdit(input){
|
||||
addInsurerColumn();
|
||||
}
|
||||
|
||||
if(res.data.policy_type_id == 1 || res.data.policy_type_id == 2 || res.data.policy_type_id == 3 || res.data.policy_type_id == 4 || res.data.policy_type_id == 5 || res.data.policy_type_id == 6 || res.data.policy_type_id == 7){
|
||||
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false);
|
||||
}else{
|
||||
$('#is_cd_reduce_from_bds').prop('disabled',false);
|
||||
}
|
||||
// if(res.data.policy_type_id == 1 || res.data.policy_type_id == 2 || res.data.policy_type_id == 3 || res.data.policy_type_id == 4 || res.data.policy_type_id == 5 || res.data.policy_type_id == 6 || res.data.policy_type_id == 7){
|
||||
// $('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false);
|
||||
// }else{
|
||||
// $('#is_cd_reduce_from_bds').prop('disabled',false);
|
||||
// }
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
@ -2336,8 +2336,13 @@
|
||||
// console.log('variance', variance);
|
||||
|
||||
// $('#variance_' + input).val(!isNaN(variance) && isFinite(variance) ? variance.toFixed(2) : '0.00');
|
||||
let policy_type_id = $('#policy_type_id').val();
|
||||
|
||||
checkCDAmountForBasePremium(input);
|
||||
if(policy_type_id > 7){
|
||||
checkCDAmountForBasePremium(input);
|
||||
}else{
|
||||
console.log("First Skip the Ajax Call these are group policies");
|
||||
}
|
||||
setCoPremiums(input);
|
||||
|
||||
console.log('############################## END AMOUNT CALCULATION ############################################')
|
||||
@ -3105,6 +3110,7 @@
|
||||
let unique_id = $(input).data('count');
|
||||
let client_id = $('#client_id').val();
|
||||
let client_type = $('#client_type').val();
|
||||
let policy_type_id = $('#policy_type_id').val();
|
||||
let insurer_id = $(input).find('option:selected').attr('data-id');
|
||||
let insurer_branch_id = $(input).find('option:selected').attr('data-bid');
|
||||
|
||||
@ -3115,7 +3121,7 @@
|
||||
console.log('follow_insurer_id unique_id', unique_id);
|
||||
|
||||
if(client_id && insurer_id){
|
||||
if(client_type == 1){
|
||||
if(client_type == 1 && policy_type_id > 7){
|
||||
$.ajax({
|
||||
url: '<?= base_url("/util/getCDAccNoByClientAndInsurer/") ?>' + client_id + '/' + insurer_id + '/' + insurer_branch_id,
|
||||
type: "GET",
|
||||
@ -3323,8 +3329,10 @@
|
||||
|
||||
$("#inception_form_id").submit(function(event) {
|
||||
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
let policy_type_id = $('#policy_type_id').val();
|
||||
var isValid = $('#inception_form_id').parsley().validate();
|
||||
var client_type_id = $('#client_type').val();
|
||||
var policy_status = $('#policy_status').val();
|
||||
@ -3345,7 +3353,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if(client_type_id == 1 && policy_status == 'completed'){
|
||||
if(client_type_id == 1 && policy_status == 'completed' && policy_type_id > 7){
|
||||
|
||||
let isAnyDropdownSelected = $('select[name="cd_ac_no_for_child[]"]').filter(function() {
|
||||
return $(this).val() !== "";
|
||||
@ -4833,6 +4841,9 @@
|
||||
|
||||
console.log('#################################### Check CD Amount For Base Premium ####################################');
|
||||
|
||||
let policy_type_id = $('#policy_type_id').val();
|
||||
console.log("policy_type_id ", policy_type_id);
|
||||
|
||||
console.log(input)
|
||||
let client_type = $('#client_type').val();
|
||||
console.log('client type', client_type);
|
||||
@ -4845,7 +4856,7 @@
|
||||
|
||||
// return;
|
||||
|
||||
if(client_type == 1){
|
||||
if(client_type == 1 && policy_type_id > 7){
|
||||
|
||||
let current_total_amt = $('#base_cd_amount').val() ?? 0;
|
||||
console.log('current_total_amt', current_total_amt);
|
||||
@ -4930,6 +4941,8 @@
|
||||
toastr.error('An error occurred while checking the CD amount.', 'ERROR');
|
||||
});
|
||||
|
||||
}else{
|
||||
console.log("Skip the Ajax Call these are group policies");
|
||||
}
|
||||
|
||||
console.log('#################################### END Check CD Amount For Base Premium ####################################');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user