nhance/app/Models/RFQModel.php

88 lines
3.0 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class RFQModel extends Model
{
protected $table = 'rfq';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
'id',
'type',
'lead_id',
'json',
"registration_json",
'created_at',
'created_by',
'updated_at',
'updated_by',
'is_active'
];
// 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 getRFQTableDataWithLeadIDAndType($lead_id, $type){
return $this->select('
leads.*,
insurers.name as insurer_name,
insurer_branch.branch_name as insurer_branch_name,
tpa.name as tpa_name,
tpa_branch.branch_name as tpa_branch_name,
policy_type.policy_type,
rfq.json,
rfq.registration_json
')
->join('leads', 'rfq.lead_id = leads.id')
->join('policy_type', 'leads.policy_type_id = policy_type.id')
->join('insurers', 'leads.insurer_id = insurers.id', 'left')
->join('insurer_branch', 'leads.insurer_branch_id = insurer_branch.id', 'left')
->join('tpa', 'leads.tpa_id = tpa.id', 'left')
->join('tpa_branch', 'leads.tpa_branch_id = tpa_branch.id', 'left')
->where('rfq.lead_id', $lead_id)
// ->where('rfq.type', $type)
->where('rfq.is_active', 1)
->orderBy('rfq.id', 'desc')
->first();
}
}