95 lines
2.7 KiB
PHP
95 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class LeadsModel extends Model
|
|
{
|
|
protected $table = 'leads';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = [
|
|
'id',
|
|
'lead_type',
|
|
'issuer',
|
|
'client_type',
|
|
'client_name',
|
|
'client_short_name',
|
|
'entity_type_id',
|
|
'client_code',
|
|
'cost_center',
|
|
'pan',
|
|
'gst',
|
|
'branch_name',
|
|
'branch_code',
|
|
'contact_person_name',
|
|
'contact_person_mobile',
|
|
'client_id',
|
|
'client_branch_id',
|
|
'source_policy_id',
|
|
'policy_type_id',
|
|
'salse_person_id',
|
|
'status',
|
|
'notes',
|
|
'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 getLeadDataForLising(){
|
|
|
|
return $this->select('
|
|
leads.*,
|
|
kyc_entity_type.name as entity_type,
|
|
policy_type.policy_type,
|
|
user_profiles.first_name as salse_person_name
|
|
')
|
|
->join('kyc_entity_type', 'leads.entity_type_id = kyc_entity_type.id', 'left')
|
|
->join('user_profiles', 'leads.salse_person_id = user_profiles.id', 'left')
|
|
->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left')
|
|
->where('leads.is_active', 1)
|
|
->where('leads.is_active', 1)
|
|
->where('leads.is_active', 1)
|
|
->findAll();
|
|
|
|
}
|
|
|
|
|
|
}
|