nhance/app/Models/ClientModel.php

68 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
use App\Models\ClientPolicyModel;
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",
];
//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_policy.id','p.name'])
->join('policies p', 'p.id = client_policy.policy_id')
->where('client_policy.client_id',$client['id'])
->where('client_policy.is_active', 1)
->findAll();
$client['policies'] = $clientPolicies;
}
//print_r(($clients));die();
return $clients;
}
public function getCreatedByUserName(){
return $this->db->table('clients')
->select('clients.*')
->select('user_profiles.first_name as user_name')
->join('user_profiles', 'user_profiles.id = clients.created_by')
->get()
->getResult();
}
}