127 lines
4.0 KiB
PHP
127 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class BdsPlacementModel extends Model
|
|
{
|
|
protected $table = 'bds_installment_payment_details';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = [
|
|
'id',
|
|
'pt_id',
|
|
'lead_id',
|
|
'installment_amount',
|
|
'payment_date',
|
|
'utr_no',
|
|
'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 getClientInstallmentDetails()
|
|
{
|
|
|
|
$builder = $this->db->table("bds_installment_payment_details bipd")
|
|
->select("bipd.*, ct.client_name,ct.short_name, cb.branch_name, leads.salse_person_id,cp.policy_no")
|
|
->join("policy_transaction pt", "pt.id = bipd.pt_id")
|
|
->join("clients ct", "ct.id = pt.client_id")
|
|
->join("client_branch cb", "cb.id = pt.client_branch_id")
|
|
->join("leads", "leads.id = bipd.lead_id")
|
|
->join("client_policy cp","cp.id = pt.client_policy_id")
|
|
->where("bipd.is_active", 1)
|
|
->where("bipd.payment_date", date('Y-m-d', strtotime('+15 days')));
|
|
|
|
$data = $builder->get()->getResultArray();
|
|
|
|
// Loop through to extract sales person details
|
|
foreach ($data as &$row) {
|
|
$sales_person_ids = json_decode($row['salse_person_id'], true);
|
|
$sales_person_id = $sales_person_ids[0] ?? null;
|
|
|
|
if ($sales_person_id) {
|
|
$user = $this->db->table('user_profiles')
|
|
->select('email') // or whatever field
|
|
->where('id', $sales_person_id)
|
|
->get()
|
|
->getRowArray();
|
|
|
|
$row['sales_person'] = $user['email'] ?? 'N/A';
|
|
} else {
|
|
$row['sales_person'] = 'Not Assigned';
|
|
}
|
|
|
|
$head = $this->db->table('user_profiles')
|
|
->select('email') // or whatever field
|
|
->where('role', 5)
|
|
->where('is_active',1)
|
|
->get()
|
|
->getResultArray();
|
|
|
|
|
|
$row['heads'] = $head;
|
|
|
|
$admin = $this->db->table('user_profiles')
|
|
->select('email')
|
|
->where("is_active",1)
|
|
->where("role",1)
|
|
->get()
|
|
->getResultArray();
|
|
|
|
$row['admins'] = $admin;
|
|
|
|
$buisenessTeam = $this->db->table("user_teams ut")
|
|
->select("up.email")
|
|
->join('user_profiles up','up.id = ut.user_id and up.is_active = 1')
|
|
->where("ut.team_id",7)
|
|
->where("ut.is_active",1)
|
|
->get()
|
|
->getResultArray();
|
|
|
|
$row['buisness_team'] = $buisenessTeam;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $data;
|
|
}
|
|
}
|