<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Dashboard extends CI_Controller {

	 function __construct()
     {
          parent::__construct();
          $this->load->database();
          $this->load->helper('url');
          $this->load->library('session');
          $this->load->model('dashboard_model');
          $this->load->model('common');
          $this->load->model('geofence_model');
     }

     public function index()
     {
           $data["employsCount"] = $this->common->readnumberofdocumentsincollectionbetween("Employs");
           $data["driversCount"] = $this->common->readnumberofdocumentsincollectionbetween("Users", "userRole", "=", "driver");
           $data["customersCount"] = $this->common->readnumberofdocumentsincollectionbetween("Users", "userRole", "=", "user");
           $data["tripsCount"] = $this->common->readnumberofdocumentsincollectionbetween("Bookings", "bookingDate", ">", strtotime(date("Y/m/d"))*1000 , "bookingDate", "<", time()*1000);
           $data["bookings"] = $this->common->readdatafromcollectionbetween("Bookings", "bookingDate" , ">", strtotime(date("Y/m/d"))*1000, "bookingDate" , "<", time()*1000);
           
           $data['reminderlist']= $this->common->readdatafromcollectionwhereclause("Reminder");
           $data['drivers'] = $this->common->readdatafromcollectionwhereclause("Users", "userRole", "=", "driver");
     
         
  
         $this->template->template_render('dashboard',$data);
     }
     
	
  public function iechart()
  {
      $data= $this->common->get_iechartdata();
      $res = "['" . implode ( "', '", array_keys($data)) . "']";
      $income = "['" . implode ( "', '", array_column($data, 'income')) . "']";
      $expense = "['" . implode ( "', '", array_column($data, 'expense')) . "']";
      echo json_encode(array('res'=>$res,'admin'=>$income,'driver'=>$expense));
  }
  public function remindermark()
  {
      $data = array('r_isread' => 1);
      $this->db->where('r_id',$this->input->post('r_id'));
      echo $this->db->update('reminder',$data);
  }
     
}
