122 lines
4.0 KiB
PHP
Executable File
122 lines
4.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class InsurerModel extends Model
|
|
{
|
|
protected $table = 'insurers';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = [
|
|
"id",
|
|
"type",
|
|
"category",
|
|
"name",
|
|
"short_name",
|
|
"insurer_logo",
|
|
"insurer_claim_form",
|
|
"insurer_claim_form_original_name",
|
|
"created_by",
|
|
"updated_by",
|
|
"is_active",
|
|
"addition_add_day",
|
|
"is_multi_event",
|
|
"deletion_add_day",
|
|
|
|
];
|
|
|
|
|
|
|
|
public function getCreatedByUserName()
|
|
{
|
|
|
|
return $this->db->table('insurers')
|
|
->select('insurers.*')
|
|
// ->select('user_profiles.first_name as user_name')
|
|
// ->join('user_profiles', 'user_profiles.id = clients.created_by')
|
|
->get()
|
|
->getResult();
|
|
}
|
|
|
|
// public function getInsurerName($insurerId, $client_id)
|
|
// {
|
|
// // Fetch the insurer name based on the insurer ID
|
|
// $query = $this->db->table('client_policy')
|
|
// ->select('insurers.id, insurers.name, cd_master.cd_ac_no as cd_master_account_no')
|
|
// ->join('insurers', 'insurers.id = client_policy.insurer_id')
|
|
// ->join('cd_master', 'cd_master.insurer_id = insurers.id AND cd_master.client_id = client_policy.client_id')
|
|
// ->where('client_policy.insurer_id', $insurerId)
|
|
// ->where('client_policy.client_id', $client_id)
|
|
// ->where('cd_master.id = client_policy.cd_ac_pk')
|
|
// ->where('cd_master.is_active', 1)
|
|
// ->get();
|
|
|
|
// if ($query->resultID->num_rows > 0) {
|
|
// $result = $query->getRow();
|
|
// return $result;
|
|
// }
|
|
|
|
// return null; // or handle accordingly if the insurer is not found
|
|
// }
|
|
|
|
public function getInsurerName($insurerId, $client_id)
|
|
{
|
|
$builder = $this->db->table('client_policy')
|
|
->select('
|
|
insurers.id,
|
|
insurers.name,
|
|
insurers.short_name,
|
|
cd_master.cd_ac_no AS cd_master_account_no
|
|
')
|
|
->join('insurers', 'insurers.id = client_policy.insurer_id')
|
|
->join(
|
|
'cd_master',
|
|
'cd_master.insurer_id = insurers.id
|
|
AND cd_master.client_id = client_policy.client_id
|
|
AND cd_master.id = client_policy.cd_ac_pk
|
|
AND cd_master.is_active = 1'
|
|
)
|
|
->where('client_policy.insurer_id', $insurerId);
|
|
|
|
// Handle raw client_id vs MD5
|
|
if (!empty($client_id)) {
|
|
if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) {
|
|
$builder->where('MD5(client_policy.client_id)', $client_id);
|
|
} else {
|
|
$builder->where('client_policy.client_id', $client_id);
|
|
}
|
|
}
|
|
|
|
$result = $builder
|
|
->groupBy([
|
|
'insurers.id',
|
|
'cd_master.cd_ac_no'
|
|
])
|
|
->limit(1)
|
|
->get()
|
|
->getRow();
|
|
|
|
return $result ?? null;
|
|
}
|
|
|
|
|
|
public function getInsurerTemplateByInsurerID($insurer_id)
|
|
{
|
|
$insurer_data = $this->db->table('insurer_excel_export_template')
|
|
->select('insurer_excel_export_template.*, insurers.name as insurer_name, insurers.is_multi_event')
|
|
// ->select('CASE WHEN insurers.is_multi_event = 1 THEN "All" ELSE insurer_excel_export_template.event_name END as event_name', false)
|
|
->select('insurer_excel_export_template.type_name, insurer_excel_export_template.jsoncolumns, policy_type.policy_type')
|
|
->join('insurers', 'insurers.id = insurer_excel_export_template.insurer_id')
|
|
->join('policy_type', 'policy_type.id = insurer_excel_export_template.policy_type_id')
|
|
->where('insurers.id', $insurer_id)
|
|
->where('insurers.is_active', 1)
|
|
->where('insurer_excel_export_template.is_active', 1)
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $insurer_data;
|
|
}
|
|
}
|
|
|
|
|