nhance/app/Models/TicketMasterModel.php

149 lines
4.5 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class TicketMasterModel extends Model
{
protected $table = 'ticket_master';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
'id',
'ticket_type_id',
'claim_status_id',
'acm_id',
'insurer_id',
'tpa_id',
'client_id',
'priority',
'policy_no',
'emp_code',
'tpa_no',
'emp_name',
'insured_name',
'relationship',
'emp_mobile',
'emp_mail',
'mode_of_intimation',
'claim_type',
'hospital_name',
'doa',
'dod',
'claim_amount',
'pod_no',
'created_by',
'updated_by',
'created_at',
'updated_at',
'date_of_join',
'date_of_incep',
'dob',
'date_of_accident',
'date_of_death',
'date_of_intimat',
'si_amt',
'is_active',
'claim_number',
'emp_id',
'insured_emp_id',
];
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = ["checkAndADDCreatedByValue"];
protected $afterInsert = [];
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
protected function checkAndADDCreatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['created_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['created_by'] = get_session_userid();
}
return $data;
}
protected function checkAndUpdateUpdatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['updated_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['updated_by'] = get_session_userid();
}
return $data;
}
public function getTemplateDataByStatusID($claim_status_id)
{
$template_data = $this->table('ticket_claim_status')
->select('ticket_mail_template.*')
->join('ticket_mail_template', 'ticket_mail_template.trigger_type = ticket_claim_status.trigger_type')
->where('ticket_mail_template.is_active', 1)
->where('ticket_claim_status.is_active', 1)
->where('ticket_claim_status.id', $claim_status_id)
->get()
->getResultArray();
return $template_data;
}
public function getTemplateDataByTicketID($ticket_id)
{
$template_data = $this
->select("ticket_mail_template.*, ticket_master.emp_mail")
->join('ticket_claim_status', 'ticket_master.claim_status_id = ticket_claim_status.id and ticket_claim_status.is_active = 1')
->join('ticket_mail_template', '
ticket_claim_status.trigger_type = ticket_mail_template.trigger_type
and ticket_claim_status.ticket_type = ticket_mail_template.ticket_type
and ticket_mail_template.is_active = 1')
->where('ticket_master.id', $ticket_id)
->where('ticket_master.is_active', 1)
->first();
return $template_data;
}
public function getTicketDataByTicketID($ticket_id)
{
$ticket_data = $this->select("
ticket_master.*,
user_profiles.first_name as acm,
user_profiles.mobile as acm_mobile,
user_profiles.email as acm_email,
clients.common_mails,
clients.client_name,
insurers.name as insurer_name,
tpa.name as tpa_name
")
->join('clients', 'ticket_master.client_id = clients.id', 'left')
->join('insurers', 'ticket_master.insurer_id = insurers.id', 'left')
->join('tpa', 'ticket_master.tpa_id = tpa.id', 'left')
->join('user_profiles', 'ticket_master.acm_id = user_profiles.id', 'left')
->where('ticket_master.id', $ticket_id)
->where('ticket_master.is_active', 1)
->first();
return $ticket_data;
}
}