<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

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


     public function delete_canteen_record($id) {
        // Assuming 'canteen_records' is your database table name
        // echo "$id";
        $this->db->where('id', $id);
        $this->db->delete('canteen');
    }
    
    public function get_canteen_detail_list($school_id = null)
    {

        $this->db->select('CN.*, S.school_name As schoolName,E.name As canteen_operator,St.name As student_name');
        $this->db->from('canteen AS CN');
        $this->db->join('schools AS S', 'S.id = CN.school_name', 'left');
        $this->db->join('students AS St', 'St.id = CN.student_name', 'left');
   
        $this->db->join('employees AS E', 'CN.canteen_operator = E.id', 'left');

        // if ($this->session->userdata('role_id') == SUPER_ADMIN && $school_id) {
        //     $this->db->where('C.school_id', $school_id);
        // }
        // if ($this->session->userdata('role_id') != SUPER_ADMIN) {
        //     $this->db->where('C.school_id', $this->session->userdata('school_id'));
        // }

        $this->db->where('S.status', 1);
        $this->db->order_by('CN.id', 'DESC');
        return $this->db->get()->result();
  
    }
    
    
}

