donation/app/Models/HomeModel.php
2023-12-14 17:38:07 +05:30

98 lines
4.6 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class HomeModel extends Model
{
public function customers($where) {
$query = $this->db->table('customers');
$totalCustomers = $query->where($where)->countAll();
$activeCustomers = $query->where($where)->countAllResults();
$where['DATE(created_on)'] = date('Y-m-d');
$todayCustomers = $query->where($where)->countAllResults();
if ($totalCustomers > 0) {
$customer['percentage'] = ($activeCustomers / $totalCustomers) * 100;
} else {
$customer['percentage'] = 0;
}
$customer['total'] = $totalCustomers;
$customer['active'] = $activeCustomers;
$customer['today'] = $todayCustomers;
return $customer;
}
// public function invoice() {
// if (date('m') <= 3) {
// $invoice['financial_year'] = (date('Y')-1) . '-' . date('Y');
// $start_date = (date('Y')-1).'-04-01';
// $end_date = date('Y').'-03-31';
// } else {
// $invoice['financial_year'] = date('Y') . '-' . (date('Y') + 1);
// $start_date = date('Y').'-04-01';
// $end_date = (date('Y')+1).'-03-31';
// }
// $date_where = ['DATE(created_on)' => date('Y-m-d'),'isactive'=>1];
// $date_query = $this->db->table('invoice')->where($date_where)->countAllResults();
// $month_where = ['MONTH(created_on)' => date('m'),'isactive'=>1];
// $month_query = $this->db->table('invoice')->where($month_where)->countAllResults();
// $fin_year_where = ['DATE(created_on) >= ' => $start_date , 'DATE(created_on) <= ' => $end_date,'isactive'=>1];
// $fin_year_query = $this->db->table('invoice')->where($fin_year_where)->countAllResults();
// $invoice['today'] = $date_query;
// $invoice['month'] = $month_query;
// $invoice['year'] = $fin_year_query;
// return $invoice;
// }
// public function schemes(){
// $query = $this->db->table('category AS C')
// ->select('C.id,C.name,LEFT(C.name, 1) AS first_letter, COUNT(S.customer_id) AS count')
// ->join('subscription AS S', 'C.id = S.scheme_id', 'left')
// ->where(['C.isactive'=>1,'C.business_id'=>1])
// ->groupBy('C.id, S.scheme_id');
// $results = $query->get()->getResultArray();
// return $results;
// }
// public function expiring_membership_list(){
// $now = date('Y-m-d');
// $last30days = date('Y-m-d', strtotime('+30 days'));
// return $this->db->table('subscription as S')
// ->join('customers as C', 'C.customer_id = S.customer_id', 'left')
// ->join('books as BK', 'BK.book_id = S.scheme_id', 'left')
// ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left')
// ->join('category as CM', 'CM.id = BC.category_id', 'left')
// ->select('CM.name, CONCAT(C.first_name, " ", C.last_name) as customer_name, C.email as customer_email, C.mobile_no as customer_mobile, S.sub_id, S.scheme_id, S.customer_id, S.business_id, S.to_subscription, S.from_subscription, BK.title, BK.book_id,DATEDIFF(S.to_subscription, CURDATE()) as countdays,DATE_FORMAT(S.to_subscription, "%d-%m-%Y") as to_subscription_date_format')
// ->where('S.to_subscription >=', $now)
// ->where('S.to_subscription <=', $last30days)
// // ->where('BC.category_id', 5)
// ->where('LOWER(CM.name)', strtolower("Membership"))
// ->orderBy('S.to_subscription', 'ASC')
// ->groupBy('S.sub_id')
// ->get()
// ->getResultArray();
// }
// public function book_published_list(){
// $now = date('Y-m-d');
// $oneMonthAgo = date('Y-m-d', strtotime($now . ' -1 month'));
// return $this->db->table('books as B')
// ->select("B.book_id, B.title, B.created_on, B.publisher, B.author, B.publication_date, DATE_FORMAT(B.publication_date, '%d-%m-%Y') as publication_date_format, GROUP_CONCAT(CM.name, ',') as categories")
// ->join('book_categories as BC', 'BC.book_id = B.book_id and BC.isactive = 1', 'left')
// ->join('category as CM', 'BC.category_id = CM.id', 'left')
// ->where('B.created_on >=', $oneMonthAgo)
// ->where('B.created_on <=', $now)
// ->where('B.isactive', 1)
// ->orderBy('B.publication_date', 'DESC')
// ->groupBy('B.book_id')
// ->get()
// ->getResultArray();
// }
}