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


/**
 * staff Class
 *
 * @package     edusol
 * @subpackage  country
 * @author      Atif Razzaq
 * @link        http://atifrazzaq.arteck.xyz
 */

class Attendance_model extends CI_Model {

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

	 public function countpresent($id=0,$month='',$branch='') 
    {
        if(empty($branch))
        $branch =$this->report_model->getBranch()[0]['id'];
        else
        $branch = $branch;
         //var_dump($month);die;
        $data =$this->db->query("SELECT promotion.id
         FROM `studentatt` 
         INNER JOIN promotion on promotion.id=studentatt.promotion_id 
         INNER JOIN class on class.class_id=promotion.class_id 
         INNER JOIN attendancestatus on attendancestatus.id=studentatt.status_id INNER JOIN student on student.id=studentatt.student_id 
         WHERE studentatt.is_deleted=0 
         and promotion.is_active=1 
         and promotion.is_delete=0 
         and attendancestatus.id=1
         AND student.branch='$branch'
         AND left(studentatt.date,11)='$month' 
         AND class.class_id='$id' 
         ");
// var_dump($data);die;

 return $data->num_rows();
    }
    	 public function countabsnt($id=0,$month='',$branch='') 
    {
        if(empty($branch))
        $branch =$this->report_model->getBranch()[0]['id'];
        else
        $branch = $branch;
         //var_dump($month);die;
        $data =$this->db->query("SELECT promotion.id
         FROM `studentatt` 
         INNER JOIN promotion on promotion.id=studentatt.promotion_id 
         INNER JOIN class on class.class_id=promotion.class_id 
         INNER JOIN attendancestatus on attendancestatus.id=studentatt.status_id INNER JOIN student on student.id=studentatt.student_id 
         WHERE studentatt.is_deleted=0 
         and promotion.is_active=1 
         and promotion.is_delete=0 
         and attendancestatus.id=2
         AND student.branch='$branch'
         AND left(studentatt.date,11)='$month' 
         AND class.class_id='$id' 
         ");
//var_dump($data);die;

 return $data->num_rows();
    }
    	 public function countleave($id=0,$month='',$branch='') 
    {
        if(empty($branch))
        $branch =$this->report_model->getBranch()[0]['id'];
        else
        $branch = $branch;
         //var_dump($month);die;
        $data =$this->db->query("SELECT promotion.id
         FROM `studentatt` 
         INNER JOIN promotion on promotion.id=studentatt.promotion_id 
         INNER JOIN class on class.class_id=promotion.class_id 
         INNER JOIN attendancestatus on attendancestatus.id=studentatt.status_id INNER JOIN student on student.id=studentatt.student_id 
         WHERE studentatt.is_deleted=0 
         and promotion.is_active=1 
         and promotion.is_delete=0 
         and attendancestatus.id=3
         AND student.branch='$branch'
         AND left(studentatt.date,11)='$month' 
         AND class.class_id='$id' 
         ");
//var_dump($data);die;

 return $data->num_rows();
    }
    	 public function counttardy($id=0,$month='',$branch='') 
    {
        if(empty($branch))
        $branch =$this->report_model->getBranch()[0]['id'];
        else
        $branch = $branch;
         //var_dump($month);die;
        $data =$this->db->query("SELECT promotion.id
         FROM `studentatt` 
         INNER JOIN promotion on promotion.id=studentatt.promotion_id 
         INNER JOIN class on class.class_id=promotion.class_id 
         INNER JOIN attendancestatus on attendancestatus.id=studentatt.status_id INNER JOIN student on student.id=studentatt.student_id 
         WHERE studentatt.is_deleted=0 
         and promotion.is_active=1 
         and promotion.is_delete=0 
         and attendancestatus.id=4
         AND student.branch='$branch'
         AND left(studentatt.date,11)='$month' 
         AND class.class_id='$id' 
         ");
//var_dump($data);die;

 return $data->num_rows();
    }
      // for saving data in sql
    public function save($data)
	{
            
            $fields_country = array(

                            'status' =>  $data['status'],
                );
              
             return $this->db->insert('attendancestatus',$fields_country);
             
	}

    public function edit($id)
    {
           
            $this->db->where('id',$id);
     return $this->db->get('attendancestatus')->result();


    }
      // for updating data
    public function update($data)
    {
           $id=$data['id'];
            $fields_country = array(
                                      'status' =>  $data['status'],
                );
              
                    $this->db->where('id',$id);
             return $this->db->update('attendancestatus',$fields_country);
                 
    }
    // for deleting ->update recourd 0 to 1
   public function delete($id){

                $fields_country=array('is_delete'=>'1');
                $this->db->where('id',$id);
                return $this->db->update('attendancestatus',$fields_country);
   }
    

}

