<?php namespace App\Models\Admin;

use App\Models\Project\DatatableModel;

class DashboardModel extends AdminModel{	
    public function __construct(){
		parent::__construct();
    }
	
/*	public function get_followup_list($user_id){
		$pending_fp_list = [];
		$builder = $this->db->table('follow_up_detail');
		$query = $builder->select('document_type_id, 
						doc_entry_pk, 
						MAX(next_follow_up_date_time) AS next_follow_up_date_time'
					)
				->groupBy('doc_entry_pk, document_type_id')
				->get();
		$followup_list = $query->getResultArray();
		
		if($followup_list){
			foreach($followup_list as $follow_up){
				$url = get_admin_path();
				if($follow_up['document_type_id']==1){
					$fd_builder = $this->db->table('enquiry AS e');
					$fd_builder->select('e.doc_entry_pk, 
									e.document_no, 
									e.business_partner_name')
								->join('status AS s',"e.status_id=s.status_id",'inner')
								->where('e.doc_entry_pk',$follow_up['doc_entry_pk'])
								->where('e.status','Active')
								->where('e.is_deleted','No')
								->where('s.follow_up','Yes');
					if($user_id!=""){ 
						$fd_builder->where('e.handled_by_user_id',$user_id); 
					}
					$url .= '/enquiry/edit/'.$follow_up['doc_entry_pk'];
					$css_class = 'fc-event-danger fc-event-solid-info';
				}
				if($follow_up['document_type_id']==2){
					$fd_builder = $this->db->table('quotation AS q');
					$fd_builder->select('q.doc_entry_pk, 
									q.document_no, 
									q.business_partner_name')
								->join('status AS s',"q.status_id=s.status_id",'inner')
								->where('q.doc_entry_pk',$follow_up['doc_entry_pk'])
								->where('q.status','Active')
								->where('q.is_deleted','No')
								->where('s.follow_up','Yes');
					if($user_id!=""){ 
						$fd_builder->where('q.handled_by_user_id',$user_id); 
					}
					$url .= '/quotation/edit/'.$follow_up['doc_entry_pk'];
					$css_class = 'fc-event-danger fc-event-solid-primary';
				}
				$fd_query = $fd_builder->get();
				$fd_result = $fd_query->getRowArray();
				if($fd_result){
					$ts = strtotime($follow_up['next_follow_up_date_time']);
					$fd_result['follow_up_date_time'] = date('Y-m-d',$ts).'T'.date('H:i:s',$ts);
					$fd_result['document_type_id']	= $follow_up['document_type_id'];
					$fd_result['css_class']	= $css_class;
					$fd_result['url'] = $url;
					$fd_result['title'] = $fd_result['document_no'];
					$fd_result['description'] = $fd_result['business_partner_name'];
					array_push($pending_fp_list,$fd_result);
				}
			}
		}
		return $pending_fp_list;
	}*/
	
	public function get_total_member(){
		$builder = $this->db->table('member');
		$query = $builder->select('COUNT(*) AS total_rec')
						 ->where('is_deleted','No')
						 ->get();
		$result = $query->getRowArray();
		return $result['total_rec'];
	}
	
	public function get_total_plot(){
		$builder = $this->db->table('plot');
		$query = $builder->select('COUNT(*) AS total_rec')
						 ->where('is_deleted','No')
						 ->get();
		$result = $query->getRowArray();
		return $result['total_rec'];
	}
	
	public function get_total_export_registration($registration_type_id){
		$builder = $this->db->table('export_registration');
		$query = $builder->select('COUNT(*) AS total_rec')
						 ->where('registration_type_id',$registration_type_id)
						 ->where('is_deleted','No')
						 ->get();
		$result = $query->getRowArray();
		return $result['total_rec'];
	}
	
}