80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
use App\Models\ClientPolicyModel;
|
|
use App\Models\ClientBranchModel;
|
|
|
|
class ClientModel extends Model
|
|
{
|
|
protected $table = 'clients';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = [
|
|
"id",
|
|
"entity_type_id",
|
|
"client_name",
|
|
"short_name",
|
|
"pan",
|
|
"gst",
|
|
"address1",
|
|
"address2",
|
|
"city",
|
|
"state",
|
|
"pincode",
|
|
"is_download_btn",
|
|
"client_logo",
|
|
"created_by",
|
|
"updated_by",
|
|
"is_active",
|
|
"common_mails",
|
|
"hr_mails"
|
|
];
|
|
|
|
|
|
|
|
//get client and its associated policies in same array
|
|
public function clientsWithPolicies()
|
|
{
|
|
|
|
$columns = ['id', 'client_name','short_name'];
|
|
$clients = $this->select($columns)->where('is_active',1)->findAll();
|
|
|
|
foreach ($clients as &$client) {
|
|
$clientPolicyModel = new ClientPolicyModel();
|
|
$clientPolicies = $clientPolicyModel->select(['client_branch.id as branch_id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id', 'client_policy.id as client_policy_id','p.name','pt.policy_type',])
|
|
->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
|
|
->join('policies p', 'p.id = client_policy.policy_id')
|
|
->join('policy_type pt','client_policy.policy_type_id = pt.id')
|
|
->where('client_policy.client_id',$client['id'])
|
|
->where('client_policy.is_active', 1)
|
|
->where('client_policy.policy_status', 1)
|
|
->findAll();
|
|
|
|
$client['policies'] = $clientPolicies;
|
|
|
|
$clientBranchModel = new ClientBranchModel();
|
|
$clientBranchs = $clientBranchModel->select(['client_branch.id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id'])
|
|
->where('client_branch.client_id',$client['id'])
|
|
->findAll();
|
|
|
|
$client['branchs'] = $clientBranchs;
|
|
}
|
|
//print_r(($clients));die();
|
|
return $clients;
|
|
}
|
|
|
|
|
|
public function getCreatedByUserName(){
|
|
|
|
return $this->db->table('clients')
|
|
->select('clients.*')
|
|
->where('is_active', 1)
|
|
->get()
|
|
->getResult();
|
|
|
|
}
|
|
|
|
}
|
|
|