donation/app/Models/HomeModel.php

41 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class HomeModel extends Model
{
public function donordetails($where) {
$totalDonors = $this->db->table('donor')
->where($where)->countAll();
$activeDonors = $this->db->table('donor')->select('donor.*, users.branch_id,users.business_id as users_business_id')
->join('users', 'users.user_id = donor.created_by AND users.business_id = donor.business_id', 'left')
->where($where)->where('donor.isactive',1)->countAllResults();
$where['DATE(donor.created_on)'] = date('Y-m-d');
$todayDonors = $this->db->table('donor')->select('donor.*, users.branch_id,users.business_id as users_business_id')
->join('users', 'users.user_id = donor.created_by AND users.business_id = donor.business_id', 'left')
->where($where)->where('donor.isactive',1)->countAllResults();
if ($totalDonors > 0) {
$final['percentage'] = ($activeDonors / $totalDonors) * 100;
} else {
$final['percentage'] = 0;
}
$final['total'] = $totalDonors;
$final['active'] = $activeDonors;
$final['today'] = $todayDonors;
return $final;
}
public function getbranchid($bwhere){
$query = $this->db->table('users');
$result = $query->select('branch_id')->where($bwhere)->get()->getRow();
return $result ? (int)$result->branch_id : 0;
}
}