nhance/app/Models/NonEbTicketMasterModel.php
2026-03-31 12:04:35 +05:30

88 lines
4.1 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class NonEbTicketMasterModel extends Model
{
protected $table = 'non_eb_ticket_master';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
'id', 'acm_id', 'client_id', 'branch_id', 'client_policy_id', 'policy_type_id',
'policy_no', 'policy_start_date', 'policy_end_date', 'insurer_id',
'nature_of_loss', 'loss_description', 'loss_location', 'loss_date', 'loss_estimate',
'intimation_recd_date', 'intimated_to_insurer_date', 'nhance_claim_ref_no', 'claim_number',
'claim_status_id', 'surveyor_file_ref_no',
'surveyor_name', 'surveyor_contact_person', 'surveyor_contact_number', 'surveyor_email', 'lor', 'surveyor_remarks',
'insured_contact_name', 'insured_contact_number', 'insured_contact_email',
'google_drive_links', 'documents_required', 'documents_submitted', 'pending_documents', 'eta_for_documents',
'loss_assessed_value', 'settled_amount', 'settlement_utr',
'asset_file', 'closure_remark', 'required_docs',
'priority', 'is_active', 'created_by', 'updated_by', 'last_updated_by', 'created_at', 'updated_at'
];
protected $allowCallbacks = true;
protected $beforeInsert = ['checkAndADDCreatedByValue'];
protected $beforeUpdate = ['checkAndUpdateUpdatedByValue'];
protected function checkAndADDCreatedByValue(array $data)
{
$data['data']['created_by'] = get_session_userid();
return $data;
}
protected function checkAndUpdateUpdatedByValue(array $data)
{
$data['data']['updated_by'] = get_session_userid();
return $data;
}
public function getTicketDataByTicketID($ticket_id)
{
return $this->select([
'non_eb_ticket_master.*',
'c.client_name', 'c.short_name',
'i.name as insurer_name',
'tcs.claim_status', 'tcs.display_name as status_display_name',
'pt.policy_type as policy_type_name',
'up.first_name as acm', 'up.mobile as acm_mobile',
'c.common_mails',
'cb.branch_name'
])
->join('clients c', 'c.id = non_eb_ticket_master.client_id AND c.is_active = 1', 'left')
->join('client_branch cb', 'cb.id = non_eb_ticket_master.branch_id', 'left')
->join('insurers i', 'i.id = non_eb_ticket_master.insurer_id AND i.is_active = 1', 'left')
->join('ticket_claim_status tcs', 'tcs.id = non_eb_ticket_master.claim_status_id AND tcs.is_active = 1', 'left')
->join('policy_type pt', 'pt.id = non_eb_ticket_master.policy_type_id AND pt.is_active = 1', 'left')
->join('user_profiles up', 'up.id = non_eb_ticket_master.acm_id', 'left')
->where('non_eb_ticket_master.id', $ticket_id)
->where('non_eb_ticket_master.is_active', 1)
->first();
}
public function getTemplateDataByTicketID($ticket_id, $status_id = null)
{
$status_join = $status_id
? 'tcs.id = ' . (int)$status_id . ' AND tcs.is_active = 1'
: 'tcs.id = non_eb_ticket_master.claim_status_id AND tcs.is_active = 1';
return $this->select([
'tmt.template_name', 'tmt.subject', 'tmt.mail_content', 'tmt.is_auto_mail', 'tmt.trigger_type',
'non_eb_ticket_master.insured_contact_email',
'non_eb_ticket_master.insured_contact_name',
'non_eb_ticket_master.policy_type_id',
'tcs.claim_status', 'tcs.trigger_type as status_trigger_type'
])
->join('ticket_claim_status tcs', $status_join, 'left')
->join('ticket_mail_template tmt', 'tmt.ticket_type = non_eb_ticket_master.policy_type_id AND tmt.trigger_type = tcs.trigger_type AND tmt.is_active = 1', 'left')
->where('non_eb_ticket_master.id', $ticket_id)
->where('non_eb_ticket_master.is_active', 1)
->first();
}
}