<?php
class TransportModel extends CI_Model{
    
    public function get_item_data($id,$table){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('id',$id);
        $info=$this->db->get()->result_array();
        return $info;     
    }
    
    public function get_data($table){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $info=$this->db->get()->result_array();
        return $info;        
    }
    
    
    public function get_desc_data($table){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->order_by("id","DESC");
        $info=$this->db->get()->result_array();
        return $info;        
    }
    
    public function insert_data($data_array,$table){
        $this->db->insert($table,$data_array);
        return $this->db->insert_id();
    }

    public function update_item_data($item_id,$data_array_update,$table){
        $info =array();	
        $this->db->where("id",$item_id);
        $info= $this->db->update($table,$data_array_update);
        return $info;
    }
    
    public function check_vehicle_driver_exist($driver_contact_no,$driver_name,$driver_table){
        $info=array();
        $this->db->select('*');
        $this->db->from($driver_table);
        $this->db->where('driver_contact_no',$driver_contact_no);
        $this->db->where('driver_name',$driver_name);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function get_student_courses_data($acedemic_session){
        $table='student_courses_data';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function student_session_info($sid,$acedemic_session){
        $table='student_courses_data';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('sid',$sid);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function check_route_exist($route_title,$route_start_point,$route_end_point,$routes_table){
        $info=array();
        $this->db->select('*');
        $this->db->from($routes_table);
        $this->db->where('route_title',$route_title);
        $this->db->where('route_start',$route_start_point);
        $this->db->where('route_end',$route_end_point);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function check_vehicle_exist($vehicle_number,$vehicle_model,$rcnumber,$vehicle_componey,$no_of_seats,$table){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('vehicle_number',$vehicle_number);
        $this->db->where('vehicle_model',$vehicle_model);
        $this->db->where('vehicle_rc_number',$rcnumber);
        $this->db->where('vehicle_componey',$vehicle_componey);
        $this->db->where('number_of_seats',$no_of_seats);
        $info=$this->db->get()->result_array();
        return $info;
    }
        
    public function get_student_info_for_ac_sesssion($sid,$acedemic_session){
        $table='transport_student_report';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('sid',$sid);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;
    }
            
    public function get_transport_fee($sid,$acedemic_session){
        $table='transport_fee';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('sid',$sid);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;
    }        
    
    public function get_prev_bal_fee_amount($sid,$acedemic_session){
        $table='transport_fee';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('balance_fee_status',1);
        $this->db->where('sid',$sid);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function get_prev_extra_fee_amount($sid,$acedemic_session){
        $table='transport_fee';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('extra_fee_status',1);
        $this->db->where('sid',$sid);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function check_fee_data_exist($sid,$acedemic_session,$status_1,$status_2,$status_3,$status_4,$status_5,$status_6,$status_7,$status_8,$status_9,$status_10,$status_11,$status_12){
        
        $table='transport_fee';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('january',$status_1);
        $this->db->where('february',$status_2);
        $this->db->where('march',$status_3);
        $this->db->where('april',$status_4);
        $this->db->where('may',$status_5);
        $this->db->where('june',$status_6);
        $this->db->where('july',$status_7);
        $this->db->where('august',$status_8);
        $this->db->where('september',$status_9);
        $this->db->where('october',$status_10);
        $this->db->where('november',$status_11);
        $this->db->where('december',$status_12);
        $this->db->where('sid',$sid);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function get_student_course_info($sid,$acedemic_session){
        $table='student_courses_data';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('sid',$sid);
        $this->db->where('acedemic_session',$acedemic_session);
        $info=$this->db->get()->result_array();
        return $info;       
    }
    public function update_student_info($sid,$acedemic_session,$data_array_update){
        $table='transport_student_report';
        $info =array();	
        $this->db->where("sid",$sid);
        $this->db->where("acedemic_session",$acedemic_session);
        $info= $this->db->update($table,$data_array_update);
        return $info;
    }
    
    public function get_transport_inv_comb_data($id,$acedemic_session){
        $sql="SELECT  transport_fee.*,student_courses_data.class,student_courses_data.section,student_courses_data.course_id,student.student_name,student.father_name FROM  transport_fee LEFT JOIN student ON student.id= transport_fee.sid LEFT JOIN student_courses_data ON student_courses_data.sid=transport_fee.sid WHERE student_courses_data.acedemic_session='$acedemic_session' AND transport_fee.id='$id'";
        $query=$this->db->query($sql);        
        return $query->result_array();
    }
    
    public function get_student_transport_comb_info_for_ac_sesssion($sid,$acedemic_session){
        $sql="SELECT transport_student_report.*,transport_routes.route_title FROM transport_student_report LEFT JOIN  transport_routes ON transport_routes.id=transport_student_report.route_no WHERE transport_student_report.sid='$sid' AND transport_student_report.acedemic_session='$acedemic_session'";
        $query=$this->db->query($sql);        
        return $query->result_array();
    }
    
    public function delete_item($id,$table){
        $this->db->where('id',$id);
        $this->db->delete($table);
        return $this->db->affected_rows(); 
    }
    
    public function get_transport_deleted_invoices_comb_data($acedemic_session){
        $sql="SELECT  transport_fee_deleted.*,student_courses_data.class,student_courses_data.section,student_courses_data.course_id,student.student_name,student.father_name,school_staff.salutation as deleted_by_salutation,school_staff.name as deleted_by_name FROM  transport_fee_deleted LEFT JOIN student ON student.id= transport_fee_deleted.sid LEFT JOIN student_courses_data ON student_courses_data.sid=transport_fee_deleted.sid LEFT JOIN school_staff ON school_staff.id=transport_fee_deleted.deleted_by WHERE student_courses_data.acedemic_session='$acedemic_session' ORDER BY transport_fee_deleted.id DESC";
        $query=$this->db->query($sql);        
        return $query->result_array();
    }
    
    
    public function get_transport_invoices_comb_data($acedemic_session){
        $sql="SELECT  transport_fee.*,student_courses_data.class,student_courses_data.section,student_courses_data.course_id,student.student_name,student.father_name,school_staff.salutation as deleted_by_salutation,school_staff.name as deleted_by_name FROM  transport_fee LEFT JOIN student ON student.id= transport_fee.sid LEFT JOIN student_courses_data ON student_courses_data.sid=transport_fee.sid LEFT JOIN school_staff ON school_staff.id=transport_fee.cat_by WHERE student_courses_data.acedemic_session='$acedemic_session' ORDER BY transport_fee.id DESC";
        $query=$this->db->query($sql);        
        return $query->result_array();
    }
    
    
    public function get_invoice_data($invoice_id,$table){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('invoice_id',$invoice_id);
        $info=$this->db->get()->result_array();
        return $info;
    }
    
}