
    <?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');
    
        class Financialreports_model extends CI_Model {
    
        protected $balance_group;
        protected $balance_type;  
        
        public function __construct() {
            parent::__construct();
        }
   
    public function getFeesummary($start_date, $end_date) {
        $this->db->select('
            student_fees_master.*,
            student_fees_master.id,
            student_fees_master.created_at as invoice_date,
            fee_groups_feetype.amount as invoice_amount,
            fee_groups.name as fee_group_name,
            feetype.type as fee_type,
            students.firstname,
            students.lastname,
            classes.class,
            sections.section,
            glledger_account.gl_code,
            glledger_account.name as gl_account_name,
            glledger_account.account_type
        ');
        
        $this->db->from('student_fees_master');
        $this->db->join('fee_session_groups', 'fee_session_groups.id = student_fees_master.fee_session_group_id');
        $this->db->join('fee_groups', 'fee_groups.id = fee_session_groups.fee_groups_id');
        $this->db->join('fee_groups_feetype', 'fee_groups_feetype.fee_groups_id = fee_groups.id', 'left');
        $this->db->join('feetype', 'feetype.id = fee_groups_feetype.feetype_id', 'left');
        $this->db->join('student_session', 'student_session.id = student_fees_master.student_session_id');
        $this->db->join('students', 'students.id = student_session.student_id');
        $this->db->join('classes', 'classes.id = student_session.class_id');
        $this->db->join('sections', 'sections.id = student_session.section_id');
        
        // Join with glledger_account using a linking field.
        // Adjust the join condition if you are using a different field.
        $this->db->join('glledger_account', 'student_fees_master.id = glledger_account.gl_code', 'left');
        
        $this->db->where('student_fees_master.created_at >=', $start_date);
        $this->db->where('student_fees_master.created_at <=', $end_date);
        
        $this->db->order_by('student_fees_master.created_at', 'DESC');
        $query = $this->db->get();
        
        return $query->result_array();
    }
    


}
