<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Bireports extends Admin_Controller {
    function __construct() {
        parent::__construct();
    }
        public function financial() {
        $this->session->set_userdata('top_menu', 'Bi Financial Reports');
        $this->session->set_userdata('sub_menu', 'bireports/financial');
        $data['title'] = 'Search Financial';
        $data['payment_modes'] = $this->payment_methods_model->select();

        if ($this->input->server('REQUEST_METHOD') == "POST") {
            $search = $this->input->post('search');
            if ($search == "search_filter") {
                $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
                $date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
                
                // Fetch current period data (original fields maintained)
                $data['feeList'] = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
                $data['customerIncomeList'] = $this->studentfeemaster_model->customer_income($date_from, $date_to)->result_array();
                $data['feediscount'] = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
                $data['journalList'] = $this->studentfeemaster_model->getAlljournals($date_from, $date_to)->result_array();
                $data['uniformList'] = $this->studentfeemaster_model->getAlluniforms($date_from, $date_to)->result_array();
                $data['cosList'] = $this->studentfeemaster_model->getcos($date_from, $date_to)->result_array();
                $data['supplierList'] = $this->studentfeemaster_model->getAllsupliers($date_from, $date_to)->result_array();
                $data['gl_expenseList'] = $this->studentfeemaster_model->getAllexpenses($date_from, $date_to)->result_array();

                // Fetch retained earnings data (original _upto fields maintained)
                $data['feeList1'] = $this->studentfeemaster_model->getFeesummary_upto($date_from);
                $data['customerIncomeList1'] = $this->studentfeemaster_model->customer_income_upto($date_from)->result_array();
                $data['feediscount1'] = $this->studentfeemaster_model->getFeeBetweenDateCurrency_upto($date_from);
                $data['journalList1'] = $this->studentfeemaster_model->getAlljournals_upto($date_from)->result_array();
                $data['uniformList1'] = $this->studentfeemaster_model->getAlluniforms_upto($date_from)->result_array();
                $data['cosList1'] = $this->studentfeemaster_model->getcos_upto($date_from)->result_array();
                $data['supplierList1'] = $this->studentfeemaster_model->getAllsupliers_upto($date_from)->result_array();
                $data['gl_expenseList1'] = $this->studentfeemaster_model->getAllexpenses_upto($date_from)->result_array();

                // Calculate profits using helper function
                $data['net_profit'] = $this->calculate_net_profit(
                    $data['feeList'],
                    $data['customerIncomeList'],
                    $data['feediscount'],
                    $data['journalList'],
                    $data['uniformList'],
                    $data['cosList'],
                    $data['supplierList'],
                    $data['gl_expenseList']
                );

                $data['retained_earnings'] = $this->calculate_net_profit(
                    $data['feeList1'],
                    $data['customerIncomeList1'],
                    $data['feediscount1'],
                    $data['journalList1'],
                    $data['uniformList1'],
                    $data['cosList1'],
                    $data['supplierList1'],
                    $data['gl_expenseList1']
                );

                // Maintain original asset calculations
                $gl_assets_query = $this->studentfeemaster_model->getAllassets($date_from, $date_to);
                $data['assetList'] = $gl_assets_query->result_array();

                $other_assets_q = $this->studentfeemaster_model->getOtherassets($date_from, $date_to);
                $data['otherasset'] = $other_assets_q->result_array();

                // Maintain original other assets total calculation
                $total_other = 0.00;
                foreach ($data['otherasset'] as $a) {
                    $total_other += floatval($a['purchase_price']);
                }
                $data['total_other_assets'] = $total_other;

                // Maintain original settings and date values
                $data['settinglist'] = $this->setting_model->get();
                $data['settinglist1'] = $this->setting_model->get();
                $data['date_from2'] = $date_from;
                $data['date_to2'] = $date_to;
                $data['exp_title'] = 'Total Invoices From ' . $this->input->post('date_from') . " To " . $this->input->post('date_to');
            }
        }

        $this->load->view('layout/header', $data);
        $this->load->view('bireports/financial', $data);
        $this->load->view('layout/footer', $data);
    }

public function total_fees() { 
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/total_fees');
    $data['title'] = 'Search Financial';

    // load the correct model
    $this->load->model('studentfeemaster_model');
    $data['fee_groups'] = $this->studentfeemaster_model->get_fee_groups();

    $data['total_fees'] = []; // default empty

    // Only fetch results if form submitted
    if ($this->input->post('search') == 'search_filter') {
        $filters = [
            'view_mode'    => $this->input->post('view_mode'),
            'date_from'    => $this->input->post('date_from'),
            'date_to'      => $this->input->post('date_to'),
            'fee_group_id' => $this->input->post('fee_group_id'),
        ];
        $data['total_fees'] = $this->studentfeemaster_model->get_total_fee($filters);
    }

    $this->load->view('layout/header', $data);
    $this->load->view('bireports/financial/total_fees', $data);
    $this->load->view('layout/footer', $data);
}

        
public function outstanding_fees()
{
    // --- Menu setup ---
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/outstanding_fees');
    $data['title'] = 'Outstanding Fees Report';
    $data['levellist'] = $this->studentfeemaster_model->selectlvl();
    $data['currency_symbol'] = $this->customlib->getSchoolCurrencyFormat();

    // --- Default (no data) ---
    $data['outstanding_fees'] = [];
    $data['grand_total_outstanding'] = 0;

    // --- If search form is submitted ---
    if ($this->input->server('REQUEST_METHOD') == "POST") {
        $search = $this->input->post('search');
        if ($search == "search_filter") {
            $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
            $date_to   = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));

            // --- Get data from model ---
            $data['outstanding_fees'] = $this->studentfeemaster_model->get_outstanding_fees($date_from, $date_to);

            // --- Calculate grand total ---
            $grand_total = 0;
            foreach ($data['outstanding_fees'] as $row) {
                $grand_total += floatval($row['Owing_Balance']);
            }
            $data['grand_total_outstanding'] = $grand_total;

            // --- For report heading ---
            $data['exp_title'] = 'Outstanding Fees from ' . $this->input->post('date_from') . ' to ' . $this->input->post('date_to');
        }
    }

    // --- Load views ---
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/financial/outstanding_fees', $data);
    $this->load->view('layout/footer', $data);
}

public function total_uniforms_collected()  
{ 
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/total_uniforms_collected');

    $data['title'] = 'Search Financial';
    $data['levellist'] = $this->studentfeemaster_model->selectlvl();

    // load the correct model
    $this->load->model('uniformpos_model');
    $data['uniform_sales'] = $this->uniformpos_model->get_uniform_sales();  

    $this->load->view('layout/header', $data);
    $this->load->view('bireports/financial/total_uniforms_collected', $data);
    $this->load->view('layout/footer', $data);
}


public function outstanding_uniforms() {
        $this->session->set_userdata('top_menu', 'Bi Financial Reports');
        $this->session->set_userdata('sub_menu', 'bireports/outstanding_uniforms');
        $data['title'] = 'Search Financial';
        $data['levellist'] = $this->studentfeemaster_model->selectlvl();
    
        // load the correct model
        $this->load->model('studentfeemaster_model');
        $data['outstanding_uniforms'] = $this->studentfeemaster_model->get_outstanding_uniforms(); 

        $this->load->view('layout/header', $data);
        $this->load->view('bireports/financial/outstanding_uniforms', $data);
        $this->load->view('layout/footer', $data);
    }
public function feescollected_vs_uniformscollected() {
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/feescollected_vs_uniformscollected');
    $data['title'] = 'Uniform Sales Report';
    $data['payment_modes'] = $this->payment_methods_model->select();

    if ($this->input->server('REQUEST_METHOD') == "POST") {
        $search = $this->input->post('search');
        if ($search == "search_filter") {
            $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
            $date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
            
            // Fetch uniform sales data
            $data['uniformList'] = $this->studentfeemaster_model->getAlluniforms($date_from, $date_to)->result_array();
            
            // Calculate uniform sales totals
            $data['uniform_sales_total'] = 0;
            $data['uniform_items'] = [];
            
            foreach ($data['uniformList'] as $uniform) {
                $item_code = $uniform['item_code'];
                $item_name = $uniform['item_name'];
                $quantity = $uniform['quantity'];
                $amount = $uniform['amount'];
                $total = $quantity * $amount;
                
                $data['uniform_sales_total'] += $total;
                
                // Group by item code
                if (!isset($data['uniform_items'][$item_code])) {
                    $data['uniform_items'][$item_code] = [
                        'code' => $item_code,
                        'name' => $item_name,
                        'quantity' => 0,
                        'amount' => $amount,
                        'total' => 0
                    ];
                }
                
                $data['uniform_items'][$item_code]['quantity'] += $quantity;
                $data['uniform_items'][$item_code]['total'] += $total;
            }
            
            // Convert to simple array for the view
            $data['uniform_items'] = array_values($data['uniform_items']);
            
            // Maintain date values for the view
            $data['date_from'] = $date_from;
            $data['date_to'] = $date_to;
            $data['exp_title'] = 'Uniform Sales From ' . $this->input->post('date_from') . " To " . $this->input->post('date_to');
        }
    }

    $this->load->view('layout/header', $data);
    $this->load->view('bireports/financial/feescollected_vs_uniformscollected', $data);
    $this->load->view('layout/footer', $data);
}           
public function uniform_sales() 
{
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/uniform_sales');
    $data['title'] = 'Uniform Sales Report';
    $data['payment_modes'] = $this->payment_methods_model->select();

    if ($this->input->server('REQUEST_METHOD') == "POST") {
        $search = $this->input->post('search');
        if ($search == "search_filter") {
            $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
            $date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
            
            // Fetch uniform sales data
            $data['uniformList'] = $this->studentfeemaster_model->getAlluniforms($date_from, $date_to)->result_array();
            
            // Calculate uniform sales totals
            $data['uniform_sales_total'] = 0;
            $data['uniform_items'] = [];
            
            foreach ($data['uniformList'] as $uniform) {
                $item_code = $uniform['item_code'];
                $item_name = $uniform['item_name'];
                $quantity = $uniform['quantity'];
                $amount = $uniform['amount'];
                $total = $quantity * $amount;
                
                $data['uniform_sales_total'] += $total;
                
                // Group by item code
                if (!isset($data['uniform_items'][$item_code])) {
                    $data['uniform_items'][$item_code] = [
                        'code' => $item_code,
                        'name' => $item_name,
                        'quantity' => 0,
                        'amount' => $amount,
                        'total' => 0
                    ];
                }
                
                $data['uniform_items'][$item_code]['quantity'] += $quantity;
                $data['uniform_items'][$item_code]['total'] += $total;
            }
            
            // Convert to simple array for the view
            $data['uniform_items'] = array_values($data['uniform_items']);
            
            // Maintain date values for the view
            $data['date_from'] = $date_from;
            $data['date_to'] = $date_to;
            $data['exp_title'] = 'Uniform Sales From ' . $this->input->post('date_from') . " To " . $this->input->post('date_to');
        }
    }

    $this->load->view('layout/header', $data);
    $this->load->view('bireports/financial/uniform_sales', $data);
    $this->load->view('layout/footer', $data);
}

public function combined_collections() 
{
    // Set menu navigation for BI reports section
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/combined_collections');

    // Page title
    $data['title'] = 'Combined Collections Report';

    // Load required model
    $this->load->model('studentfeemaster_model');

    // Default values
    $data['view_mode'] = 'consolidated'; // default view mode
    $data['date_from'] = '';
    $data['date_to'] = '';

    // Ignore filters for now — just show everything
    try {
        $filters = [
            'view_mode' => 'consolidated',
            'date_from' => '',
            'date_to' => '',
            'fee_group_id' => ''
        ];

        // Get combined data directly
        $data['combined_data'] = $this->studentfeemaster_model->get_combined_collections($filters);

        // Get totals directly
        $data['totals'] = $this->studentfeemaster_model->get_combined_totals($filters);

    } catch (Exception $e) {
        $data['error'] = "Error fetching data: " . $e->getMessage();
    }

    // Load the view
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/financial/combined_collections', $data);
    $this->load->view('layout/footer', $data);
}

     public function outstanding_uniform() {
        $this->session->set_userdata('top_menu', 'Bi Financial Reports');
        $this->session->set_userdata('sub_menu', 'bireports/outstanding_uniform');
        $data['title'] = 'Search Financial';
        $data['payment_modes'] = $this->payment_methods_model->select();

        if ($this->input->server('REQUEST_METHOD') == "POST") {
            $search = $this->input->post('search');
            if ($search == "search_filter") {
                $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
                $date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
                
                // Fetch current period data (original fields maintained)
                $data['feeList'] = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
                $data['customerIncomeList'] = $this->studentfeemaster_model->customer_income($date_from, $date_to)->result_array();
                $data['feediscount'] = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
                $data['journalList'] = $this->studentfeemaster_model->getAlljournals($date_from, $date_to)->result_array();
                $data['uniformList'] = $this->studentfeemaster_model->getAlluniforms($date_from, $date_to)->result_array();
                $data['cosList'] = $this->studentfeemaster_model->getcos($date_from, $date_to)->result_array();
                $data['supplierList'] = $this->studentfeemaster_model->getAllsupliers($date_from, $date_to)->result_array();
                $data['gl_expenseList'] = $this->studentfeemaster_model->getAllexpenses($date_from, $date_to)->result_array();

                // Fetch retained earnings data (original _upto fields maintained)
                $data['feeList1'] = $this->studentfeemaster_model->getFeesummary_upto($date_from);
                $data['customerIncomeList1'] = $this->studentfeemaster_model->customer_income_upto($date_from)->result_array();
                $data['feediscount1'] = $this->studentfeemaster_model->getFeeBetweenDateCurrency_upto($date_from);
                $data['journalList1'] = $this->studentfeemaster_model->getAlljournals_upto($date_from)->result_array();
                $data['uniformList1'] = $this->studentfeemaster_model->getAlluniforms_upto($date_from)->result_array();
                $data['cosList1'] = $this->studentfeemaster_model->getcos_upto($date_from)->result_array();
                $data['supplierList1'] = $this->studentfeemaster_model->getAllsupliers_upto($date_from)->result_array();
                $data['gl_expenseList1'] = $this->studentfeemaster_model->getAllexpenses_upto($date_from)->result_array();

                // Calculate profits using helper function
                $data['net_profit'] = $this->calculate_net_profit(
                    $data['feeList'],
                    $data['customerIncomeList'],
                    $data['feediscount'],
                    $data['journalList'],
                    $data['uniformList'],
                    $data['cosList'],
                    $data['supplierList'],
                    $data['gl_expenseList']
                );

                $data['retained_earnings'] = $this->calculate_net_profit(
                    $data['feeList1'],
                    $data['customerIncomeList1'],
                    $data['feediscount1'],
                    $data['journalList1'],
                    $data['uniformList1'],
                    $data['cosList1'],
                    $data['supplierList1'],
                    $data['gl_expenseList1']
                );

                // Maintain original asset calculations
                $gl_assets_query = $this->studentfeemaster_model->getAllassets($date_from, $date_to);
                $data['assetList'] = $gl_assets_query->result_array();

                $other_assets_q = $this->studentfeemaster_model->getOtherassets($date_from, $date_to);
                $data['otherasset'] = $other_assets_q->result_array();

                // Maintain original other assets total calculation
                $total_other = 0.00;
                foreach ($data['otherasset'] as $a) {
                    $total_other += floatval($a['purchase_price']);
                }
                $data['total_other_assets'] = $total_other;

                // Maintain original settings and date values
                $data['settinglist'] = $this->setting_model->get();
                $data['settinglist1'] = $this->setting_model->get();
                $data['date_from2'] = $date_from;
                $data['date_to2'] = $date_to;
                $data['exp_title'] = 'Total Invoices From ' . $this->input->post('date_from') . " To " . $this->input->post('date_to');
            }
        }

        $this->load->view('layout/header', $data);
        $this->load->view('bireports/financial/outstanding_uniform', $data);
        $this->load->view('layout/footer', $data);
    }
     public function fees_uniform() {
        $this->session->set_userdata('top_menu', 'Bi Financial Reports');
        $this->session->set_userdata('sub_menu', 'bireports/fees_uniform');
        $data['title'] = 'Search Financial';
        $data['payment_modes'] = $this->payment_methods_model->select();

        if ($this->input->server('REQUEST_METHOD') == "POST") {
            $search = $this->input->post('search');
            if ($search == "search_filter") {
                $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
                $date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
                
                // Fetch current period data (original fields maintained)
                $data['feeList'] = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
                $data['customerIncomeList'] = $this->studentfeemaster_model->customer_income($date_from, $date_to)->result_array();
                $data['feediscount'] = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
                $data['journalList'] = $this->studentfeemaster_model->getAlljournals($date_from, $date_to)->result_array();
                $data['uniformList'] = $this->studentfeemaster_model->getAlluniforms($date_from, $date_to)->result_array();
                $data['cosList'] = $this->studentfeemaster_model->getcos($date_from, $date_to)->result_array();
                $data['supplierList'] = $this->studentfeemaster_model->getAllsupliers($date_from, $date_to)->result_array();
                $data['gl_expenseList'] = $this->studentfeemaster_model->getAllexpenses($date_from, $date_to)->result_array();

                // Fetch retained earnings data (original _upto fields maintained)
                $data['feeList1'] = $this->studentfeemaster_model->getFeesummary_upto($date_from);
                $data['customerIncomeList1'] = $this->studentfeemaster_model->customer_income_upto($date_from)->result_array();
                $data['feediscount1'] = $this->studentfeemaster_model->getFeeBetweenDateCurrency_upto($date_from);
                $data['journalList1'] = $this->studentfeemaster_model->getAlljournals_upto($date_from)->result_array();
                $data['uniformList1'] = $this->studentfeemaster_model->getAlluniforms_upto($date_from)->result_array();
                $data['cosList1'] = $this->studentfeemaster_model->getcos_upto($date_from)->result_array();
                $data['supplierList1'] = $this->studentfeemaster_model->getAllsupliers_upto($date_from)->result_array();
                $data['gl_expenseList1'] = $this->studentfeemaster_model->getAllexpenses_upto($date_from)->result_array();

                // Calculate profits using helper function
                $data['net_profit'] = $this->calculate_net_profit(
                    $data['feeList'],
                    $data['customerIncomeList'],
                    $data['feediscount'],
                    $data['journalList'],
                    $data['uniformList'],
                    $data['cosList'],
                    $data['supplierList'],
                    $data['gl_expenseList']
                );

                $data['retained_earnings'] = $this->calculate_net_profit(
                    $data['feeList1'],
                    $data['customerIncomeList1'],
                    $data['feediscount1'],
                    $data['journalList1'],
                    $data['uniformList1'],
                    $data['cosList1'],
                    $data['supplierList1'],
                    $data['gl_expenseList1']
                );

                // Maintain original asset calculations
                $gl_assets_query = $this->studentfeemaster_model->getAllassets($date_from, $date_to);
                $data['assetList'] = $gl_assets_query->result_array();

                $other_assets_q = $this->studentfeemaster_model->getOtherassets($date_from, $date_to);
                $data['otherasset'] = $other_assets_q->result_array();

                // Maintain original other assets total calculation
                $total_other = 0.00;
                foreach ($data['otherasset'] as $a) {
                    $total_other += floatval($a['purchase_price']);
                }
                $data['total_other_assets'] = $total_other;

                // Maintain original settings and date values
                $data['settinglist'] = $this->setting_model->get();
                $data['settinglist1'] = $this->setting_model->get();
                $data['date_from2'] = $date_from;
                $data['date_to2'] = $date_to;
                $data['exp_title'] = 'Total Invoices From ' . $this->input->post('date_from') . " To " . $this->input->post('date_to');
            }
        }

        $this->load->view('layout/header', $data);
        $this->load->view('bireports/financial/fees_uniform', $data);
        $this->load->view('layout/footer', $data);
    }
    public function searchstatement() {
        $this->session->set_userdata('top_menu', 'Financial Reports');
        $this->session->set_userdata('sub_menu', 'incomestatement/searchstatement');
        $data['title'] = 'Search Expense';
    
        // Fetch payment methods from the database
        $data['payment_modes'] = $this->payment_methods_model->select();
    
        // Process the form if a POST request
        if ($this->input->server('REQUEST_METHOD') == "POST") {
            $search = $this->input->post('search');
    
            if ($search == "search_filter") {
                // Get the form data and convert date format
                $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
                $date_to   = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
    
                // Construct the title
                $data['exp_title'] = 'Total Invoices From ' 
                    . $this->input->post('date_from') 
                    . " To " 
                    . $this->input->post('date_to');
    
                // Fetch financial data
                $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
                $data['incomeList']         = $this->income_model->search($date_from, $date_to);
                $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
                $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDateCurrency($date_from, $date_to);
                $data['customerIncomeList'] = $this->studentfeemaster_model->customer_income($date_from, $date_to)->result_array();
                $data['journalList']        = $this->studentfeemaster_model->getAlljournals($date_from, $date_to)->result_array();
    
                // Fetch supplier invoice data
                $supplier_query       = $this->studentfeemaster_model->getAllsupliers($date_from, $date_to);
                $data['supplierList'] = $supplier_query->result_array();
    
                // Fetch GL expenses from cashbook joined with GL and sub-account data
                $gl_expenses_query          = $this->studentfeemaster_model->getAllexpenses($date_from, $date_to);
                $data['gl_expenseList']     = $gl_expenses_query->result_array();
    
                // Fetch all GL accounts from glledger_account table
                $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
    
                // Fetch uniforms data using the new getAlluniforms() model method
                $data['uniformList'] = $this->studentfeemaster_model->getAlluniforms($date_from, $date_to)->result_array();

                $setting_result         = $this->setting_model->get();
                $data['settinglist']    = $setting_result;
                
                // ← NEW: Fetch Cost of Stock from item_stock table via getcos() →
                
                $cos_query            = $this->studentfeemaster_model->getcos($date_from, $date_to);
                $data['cosList']      = $cos_query->result_array();
                //
                // ← END NEW CODE
    
                // Retain date values for the form
                $data['date_from2'] = $date_from;
                $data['date_to2']   = $date_to;
            }
        }
    
        // Load views
        $this->load->view('layout/header', $data);
        $this->load->view('admin/financialreport/incomestate', $data);
        $this->load->view('layout/footer', $data);
    }
public function sales()
{ 
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/sales');

    $this->load->model('uniformpos_model');

    $data['title'] = 'Stock Levels';
    $data['uniformlist']   = $this->uniformpos_model->selectuniform();
    $data['warehouselist'] = $this->uniformpos_model->selectwarehouse();
    $data['itemlist']      = $this->uniformpos_model->selectitem();

    // Get posted filters
    $inventory_item   = $this->input->post('inventory_item');
    $search_clicked   = $this->input->post('search_clicked');

    $data['inventory_item'] = $inventory_item;

    // Defaults (empty so tables won't show unless searched)
    $data['uniform_sales'] = [];
    $data['item_stock']    = [];

    if ($search_clicked == '1') {
        if ($inventory_item === 'uniforms') {
            $from     = $this->input->post('uniform_from');
            $to       = $this->input->post('uniform_to');
            $show_all = $this->input->post('show_all');
            $warehouse = $this->input->post('warehouse');

            $data['uniform_sales'] = $this->uniformpos_model->get_uniform_stock($from, $to, $show_all, $warehouse);

        } elseif ($inventory_item === 'other') {
            $from     = $this->input->post('other_item_from');
            $to       = $this->input->post('other_item_to');
            $show_all = $this->input->post('show_all_other');

            $data['item_stock'] = $this->uniformpos_model->get_item_stock($from, $to, $show_all);
        }
    }

    $this->load->view('layout/header', $data);
    $this->load->view('bireports/uniform/sales', $data);
    $this->load->view('layout/footer', $data);
}
public function collections() 
{
    $this->session->set_userdata('top_menu', 'Bi Financial Reports');
    $this->session->set_userdata('sub_menu', 'bireports/collections');

    $data['title'] = 'uniform';
    $data['uniformlist'] = $this->uniformpos_model->selectuniform();
    $data['warehouselist'] = $this->uniformpos_model->selectwarehouse();

    $filters = [];

    if ($this->input->post('search') == 'search_filter') {
        $filters['inventory_item'] = $this->input->post('inventory_item');
        $filters['uniform_from'] = $this->input->post('uniform_from');
        $filters['uniform_to'] = $this->input->post('uniform_to');
        $filters['warehouse'] = $this->input->post('warehouse');
        $filters['date_from'] = $this->input->post('date_from');
        $filters['date_to'] = $this->input->post('date_to');
        $filters['show_all_uniforms'] = $this->input->post('show_all_uniforms');

        $data['search'] = 'search_filter';
    }

    $this->load->model('uniformpos_model');
    $data['uniform_sales'] = $this->uniformpos_model->get_uniform_stock_mvmnt($filters);

    $this->load->view('layout/header', $data);
    $this->load->view('bireports/uniform/collections', $data);
    $this->load->view('layout/footer', $data);
}

public function invoiced_vs_received() 
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Financial Reports',
        'sub_menu' => 'bireports/invoiced_vs_received',
    ]);
    $data['title'] = 'uniform';
    $data['itemcatlist'] = $this->uniformpos_model->selectitemcat();

    $this->load->model('uniformpos_model');

    // Default empty
    $data['item_issues'] = [];

    // Handle search
    if ($this->input->post('search') == 'search_filter') {
        $filters = [
            'inventory_item' => $this->input->post('inventory_item'),
            'item_id'        => $this->input->post('item_id'),
            'date_from'      => $this->input->post('date_from'),
            'date_to'        => $this->input->post('date_to'),
        ];

        $data['inventory_item'] = $filters['inventory_item'];
        $data['item_id']        = $filters['item_id'];
        $data['date_from']      = $filters['date_from'];
        $data['date_to']        = $filters['date_to'];

        $data['item_issues'] = $this->uniformpos_model->get_item_issue($filters);
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/uniform/invoiced_vs_received', $data);
    $this->load->view('layout/footer', $data);
}

public function outstanding_payments()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Financial Reports',
        'sub_menu' => 'bireports/outstanding_payments',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/uniform/outstanding_payments', $data);
    $this->load->view('layout/footer', $data);
}
public function stock_value()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Financial Reports',
        'sub_menu' => 'bireports/stock_value',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/uniform/stock_value', $data);
    $this->load->view('layout/footer', $data);
}
public function stock_alerts()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Financial Reports',
        'sub_menu' => 'bireports/stock_alerts',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/uniform/stock_alerts', $data);
    $this->load->view('layout/footer', $data);
}
public function dashboard()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Dashboard Visualizations',
        'sub_menu' => 'bireports/dashboard',
    ]);
    $data['title'] = 'dashboard';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/dashboard', $data);
    $this->load->view('layout/footer', $data);
}
public function acadash()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Dashboard Visualizations',
        'sub_menu' => 'bireports/acadash',
    ]);
    $data['title'] = 'dashboard';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/dashboard/acadash', $data);
    $this->load->view('layout/footer', $data);
}
public function attdash()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Dashboard Visualizations',
        'sub_menu' => 'bireports/attdash',
    ]);
    $data['title'] = 'dashboard';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/dashboard/attdash', $data);
    $this->load->view('layout/footer', $data);
}
public function behdash()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Dashboard Visualizations',
        'sub_menu' => 'bireports/behdash',
    ]);
    $data['title'] = 'dashboard';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/dashboard/behdash', $data);
    $this->load->view('layout/footer', $data);
}
public function taboard()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Bi Dashboard Visualizations',
        'sub_menu' => 'bireports/taboard',
    ]);
    $data['title'] = 'dashboard';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/dashboard/taboard', $data);
    $this->load->view('layout/footer', $data);
}
public function academic()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/academic',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/academic', $data);
    $this->load->view('layout/footer', $data);
}
public function attendance()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/attendance',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/attendance', $data);
    $this->load->view('layout/footer', $data);
}
public function behavioral()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/behavioral',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/behavioral', $data);
    $this->load->view('layout/footer', $data);
}
public function ipo()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/ipo',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/ipo', $data);
    $this->load->view('layout/footer', $data);
}
public function outstanding()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/outstanding',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/outstanding', $data);
    $this->load->view('layout/footer', $data);
}
public function feesoutstanding()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/feesoutstanding',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/feesoutstanding', $data);
    $this->load->view('layout/footer', $data);
}
public function profitability()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/profitability',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/profitability', $data);
    $this->load->view('layout/footer', $data);
}
public function gross()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/gross',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/gross', $data);
    $this->load->view('layout/footer', $data);
}
public function stockcons()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/stockcons',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/ipo/stockcons', $data);
    $this->load->view('layout/footer', $data);
}

public function exams()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/exams',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/learnerperfomance/exams', $data);
    $this->load->view('layout/footer', $data);
}
public function termreport()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/termreport',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/learnerperfomance/termreport', $data);
    $this->load->view('layout/footer', $data);
}
public function attendancevspass()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/attendancevspass',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/lsa/attendancevspass', $data);
    $this->load->view('layout/footer', $data);
}
public function healthyratingvsaveragescore()
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/healthyratingvsaveragescore',
    ]);
    $data['title'] = 'uniform';

    // Always populate payment modes
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Only run the filters when the form is submitted
    if ($this->input->server('REQUEST_METHOD') === 'POST'
        && $this->input->post('search') === 'search_filter'
    ) {
        // Parse and reformat dates
        $dateFromRaw = $this->input->post('date_from');
        $dateToRaw   = $this->input->post('date_to');
        $date_from   = date('Y-m-d', $this->customlib->datetostrtotime($dateFromRaw));
        $date_to     = date('Y-m-d', $this->customlib->datetostrtotime($dateToRaw));

        // Build title
        $data['exp_title']   = "Total Invoices From {$dateFromRaw} To {$dateToRaw}";
        $data['date_from2']  = $date_from;
        $data['date_to2']    = $date_to;

        // Fetch all the pieces of your report
        $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
        $data['incomeList']         = $this->income_model->search($date_from, $date_to);
        $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
        $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
        $data['customerIncomeList'] = $this->studentfeemaster_model
                                            ->customer_income($date_from, $date_to)
                                            ->result_array();
        $data['journalList']        = $this->studentfeemaster_model
                                            ->getAlljournals($date_from, $date_to)
                                            ->result_array();
        $data['supplierList']       = $this->studentfeemaster_model
                                            ->getAllsupliers($date_from, $date_to)
                                            ->result_array();
        $data['gl_expenseList']     = $this->studentfeemaster_model
                                            ->getAllexpenses($date_from, $date_to)
                                            ->result_array();
        $data['uniformList']        = $this->studentfeemaster_model
                                            ->getAlluniforms($date_from, $date_to)
                                            ->result_array();
        $data['cosList']            = $this->studentfeemaster_model
                                            ->getcos($date_from, $date_to)
                                            ->result_array();
        $data['assetList']          = $this->studentfeemaster_model
                                            ->getAllassets($date_from, $date_to)
                                            ->result_array();
        $data['otherasset']         = $this->studentfeemaster_model
                                            ->getOtherassets($date_from, $date_to)
                                            ->result_array();

        // Compute any derived totals
        $total_other = 0.0;
        foreach ($data['otherasset'] as $asset) {
            $total_other += floatval($asset['purchase_price']);
        }
        $data['total_other_assets'] = $total_other;

        // Grab GL‐master data once
        $data['glaccounts'] = $this->studentfeemaster_model->select()->result_array();
        $data['settinglist'] = $this->setting_model->get();
    }

    // Finally, load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/lsa/healthyratingvsaveragescore', $data);
    $this->load->view('layout/footer', $data);
}
public function discipline() 
{
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'BI IPO Reports',
        'sub_menu' => 'bireports/discipline',
    ]);
    
    $data['title'] = 'Discipline Report';

    // Load the model
    $this->load->model('Incidentreport_model');

    // Retrieve incident data
    $data['incidents'] = $this->Incidentreport_model->get_all_incidents();

    // Retrieve DOBs for the DOB filter
    $data['dobs'] = $this->Incidentreport_model->getAllDobs();

    // Load the views
    $this->load->view('layout/header', $data);
    $this->load->view('bireports/learnerperfomance/discipline', $data);
    $this->load->view('layout/footer', $data);
}


public function printtrialbalance() {
    // Set menu and title
    $this->session->set_userdata([
        'top_menu' => 'Financial Reports',
        'sub_menu' => 'trialbalance/searchtrialbalance',
    ]);
    $data['title'] = 'Search Trial Balance';

    // Load settings and payment modes
    $data['settinglist']   = $this->setting_model->get();
    $data['payment_modes'] = $this->payment_methods_model->select();

    // Determine report type and date range
    $data['report_type'] = $this->input->post('report_type') ?? 'summary';
    $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
    $date_to   = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));

    // Title and date labels
    $data['exp_title']  = 'Total Invoices From ' . $this->input->post('date_from') . ' To ' . $this->input->post('date_to');
    $data['date_from2'] = $date_from;
    $data['date_to2']   = $date_to;

    // Currency symbol
    $data['currency_symbol'] = $this->customlib->getSchoolCurrencyFormat();

    // Fetch all relevant financial data for trial balance
    $data['expenseList']        = $this->expense_model->search($date_from, $date_to);
    $data['incomeList']         = $this->income_model->search($date_from, $date_to);
    $data['feeList']            = $this->studentfeemaster_model->getFeesummary($date_from, $date_to);
    $data['feediscount']        = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
    $data['customerIncomeList'] = $this->studentfeemaster_model->customer_income($date_from, $date_to)->result_array();
    $data['journalList']        = $this->studentfeemaster_model->getAlljournals($date_from, $date_to)->result_array();
    $data['supplierList']       = $this->studentfeemaster_model->getAllsupliers($date_from, $date_to)->result_array();
    $data['gl_expenseList']     = $this->studentfeemaster_model->getAllexpenses($date_from, $date_to)->result_array();
    $data['uniformList']        = $this->studentfeemaster_model->getAlluniforms($date_from, $date_to)->result_array();
    $data['cosList']            = $this->studentfeemaster_model->getcos($date_from, $date_to)->result_array();
    $data['assetList']          = $this->studentfeemaster_model->getAllassets($date_from, $date_to)->result_array();
    $data['otherasset']         = $this->studentfeemaster_model->getOtherassets($date_from, $date_to)->result_array();

    // Compute total other assets
    $total_other = 0.00;
    foreach ($data['otherasset'] as $asset) {
        $total_other += floatval($asset['purchase_price']);
    }
    $data['total_other_assets'] = $total_other;

    // Load GL master accounts
    $data['glaccounts']  = $this->studentfeemaster_model->select()->result_array();

    // Render print view
    $this->load->view('print/printTrialbalance', $data);
}

    

    function studentacademicreport() {
        if (!$this->rbac->hasPrivilege('balance_fees_report', 'can_view')) {
            access_denied();
        }
        $this->session->set_userdata('top_menu', 'Fees Collection');
        $this->session->set_userdata('sub_menu', 'transaction/studentacademicreport');
        $data['title'] = 'student fee';
        $data['title'] = 'student fee';
        $class = $this->class_model->get();
        $data['classlist'] = $class;

        if ($this->input->server('REQUEST_METHOD') == "GET") {
            $this->load->view('layout/header', $data);
            $this->load->view('admin/transaction/studentAcademicReport', $data);
            $this->load->view('layout/footer', $data);
        } else {	
			
			$date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
			$date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
            $this->form_validation->set_rules('section_id', 'Section', 'trim|required|xss_clean');
            $this->form_validation->set_rules('class_id', 'Class', 'trim|required|xss_clean');
				
            if ($this->form_validation->run() == FALSE) {
                $this->load->view('layout/header', $data);
                $this->load->view('admin/transaction/studentAcademicReport', $data);
                $this->load->view('layout/footer', $data);
            } else {
                $class_id = $this->input->post('class_id');
                $section_id = $this->input->post('section_id');
                $feetype = $this->input->post('feetype');
                $feetype_arr = $this->input->post('feetype_arr');
                $student_Array = array();
                $studentlist = $this->student_model->searchByClassSection($class_id, $section_id);
                if (!empty($studentlist)) {
                    foreach ($studentlist as $key => $eachstudent) {
                        $obj = new stdClass();
                        $obj->name = $eachstudent['firstname'] . " " . $eachstudent['lastname'];
                        $obj->class = $eachstudent['class'];
                        $obj->section = $eachstudent['section'];
                        $obj->admission_no = $eachstudent['admission_no'];
                        $obj->roll_no = $eachstudent['roll_no'];
                        $obj->father_name = $eachstudent['father_name'];
                        $obj->student_session_id = $eachstudent['student_session_id'];
                        $student_session_id = $eachstudent['student_session_id'];						

                        //$student_total_fees = $this->studentfeemaster_model->getStudentFees($student_session_id,$date_from, $date_to);
                       $student_total_fees = $this->studentfeemaster_model->getStudentFeeswithDatesBetween($student_session_id,$date_from, $date_to);
					   
					   $feeList = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
					   $data['feeList'] = $feeList;

                        if (!empty($feeList)) {
							
                        if (!empty($student_total_fees)) {
                            $totalfee = 0;
                            $deposit = 0;
                            $discount = 0;
                            $balance = 0;
                            $fine = 0;
                            $fee_converted = 0;
                            $fee_paid = 0;

                            foreach ($student_total_fees as $student_total_fees_key => $student_total_fees_value) {

                                if (!empty($student_total_fees_value->fees)) {
                                    foreach ($student_total_fees_value->fees as $each_fee_key => $each_fee_value) {
                                        $totalfee = $totalfee + $each_fee_value->amount;

                                        $amount_detail = json_decode($each_fee_value->amount_detail);
										

                                        if (is_object($amount_detail)) {
                                            foreach ($amount_detail as $amount_detail_key => $amount_detail_value) {

                                                $this->db->select('*');
												$this->db->from('bank_rates');
												$query1 = $this->db->get();
												$result1 = $query1->row();

												$home_currency = $result1->home_currency;
												$foreign_currency = $result1->foreign_currency;

                                                $payment_mode = $amount_detail_value->payment_mode;
                                                $amount = $amount_detail_value->amount;
                                               
                                                $currency_symbol = $this->customlib->getSchoolCurrencyFormat();
                                                    if($payment_mode==$currency_symbol){
                                                                                                                
                                                            $this->db->select('*');
                                                            $this->db->from('bank_rates');
                                                            $this->db->where('home_currency',$payment_mode);
                                                            $query1 = $this->db->get();
                                                            $row1_rate = $query1->row();
                                                            
                                                            $home_rate = $row1_rate->home_rate;
                                                            
                                                            $fee_converted = $home_rate*$amount;
                                                            
                                                    }
                                                else{
                                                    
                                                            $this->db->select('*');
                                                            $this->db->from('bank_rates');
                                                            $this->db->where('foreign_currency',$payment_mode);
                                                            $query3 = $this->db->get();
                                                            $row1_rate2 = $query3->row();
                                                            
                                                            $foreign_currency_row1 = $row1_rate2->foreign_currency;
                                                            $foreign_rate = $row1_rate2->foreign_rate;
                                                            
                                                            $fee_converted = ($amount/$foreign_rate)*1;	
                                                            
                                                }														
                                                
                                                $deposit = $deposit +$fee_converted;
                                                $fine = $fine + $amount_detail_value->amount_fine;
                                                $discount = $discount + $amount_detail_value->amount_discount;

                                            }
                                        }
                                    }
                                }
                            }

                            $obj->totalfee = $totalfee;
                            $obj->payment_mode = $payment_mode;
                            $obj->deposit = $deposit;
                            $obj->fine = $fine;
                            $obj->discount = $discount;
                            $obj->balance = $totalfee - ($deposit + $discount);
                        } 
						else {
						

						
                            $obj->totalfee = "N/A";
                            $obj->payment_mode = "N/A";
                            $obj->deposit = "N/A";
                            $obj->fine = "N/A";
                            $obj->balance = "N/A";
                            $obj->discount = "N/A";
                        }
                        $student_Array[] = $obj;
						}
                    }
                }


                $data['student_due_fee'] = $student_Array;
				$data['date_from2'] = $date_from2;
				$data['date_to2'] = $date_to;
                // exit();
                $data['class_id'] = $class_id;
                $data['section_id'] = $section_id;
                $data['feetype'] = $feetype;
                $data['feetype_arr'] = $feetype_arr;
                $this->load->view('layout/header', $data);
                $this->load->view('admin/transaction/studentAcademicReport', $data);
                $this->load->view('layout/footer', $data);
            }
        }
    }   
	
	function printBalanceFeesByGroup() {
        if (!$this->rbac->hasPrivilege('balance_fees_report', 'can_view')) {
            access_denied();
        }
		        $setting_result = $this->setting_model->get();
                $data['settinglist'] = $setting_result;
				
        $data['title'] = 'student fee';
        $data['title'] = 'student fee';
        $class = $this->class_model->get();
        $data['classlist'] = $class;	
			
			$date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
			$date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));

                $class_id = $this->input->post('class_id');
                $section_id = $this->input->post('section_id');
                $feetype = $this->input->post('feetype');
                $feetype_arr = $this->input->post('feetype_arr');
                $student_Array = array();
                $studentlist = $this->student_model->searchByClassSection($class_id, $section_id);
                if (!empty($studentlist)) {
                    foreach ($studentlist as $key => $eachstudent) {
                        $obj = new stdClass();
                        $obj->name = $eachstudent['firstname'] . " " . $eachstudent['lastname'];
                        $obj->class = $eachstudent['class'];
                        $obj->section = $eachstudent['section'];
                        $obj->admission_no = $eachstudent['admission_no'];
                        $obj->roll_no = $eachstudent['roll_no'];
                        $obj->father_name = $eachstudent['father_name'];
                        $obj->student_session_id = $eachstudent['student_session_id'];
                        $student_session_id = $eachstudent['student_session_id'];						

                        //$student_total_fees = $this->studentfeemaster_model->getStudentFees($student_session_id,$date_from, $date_to);
                       $student_total_fees = $this->studentfeemaster_model->getStudentFeeswithDatesBetween($student_session_id,$date_from, $date_to);
					   
					   $feeList = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
					   $data['feeList'] = $feeList;

                        if (!empty($feeList)) {
							
                        if (!empty($student_total_fees)) {
                            $totalfee = 0;
                            $deposit = 0;
                            $discount = 0;
                            $balance = 0;
                            $fine = 0;
                            foreach ($student_total_fees as $student_total_fees_key => $student_total_fees_value) {


                                if (!empty($student_total_fees_value->fees)) {
                                    foreach ($student_total_fees_value->fees as $each_fee_key => $each_fee_value) {
                                        $totalfee = $totalfee + $each_fee_value->amount;

                                        $amount_detail = json_decode($each_fee_value->amount_detail);
										
                                        if (is_object($amount_detail)) {
                                            foreach ($amount_detail as $amount_detail_key => $amount_detail_value) {
                                                $deposit = $deposit + $amount_detail_value->amount;
                                                $fine = $fine + $amount_detail_value->amount_fine;
                                                $discount = $discount + $amount_detail_value->amount_discount;
                                            }
                                        }
                                    }
                                }
                            }

                            $obj->totalfee = $totalfee;
                            $obj->payment_mode = "N/A";
                            $obj->deposit = $deposit;
                            $obj->fine = $fine;
                            $obj->discount = $discount;
                            $obj->balance = $totalfee - ($deposit + $discount);
                        } 
						else {
						

						
                            $obj->totalfee = "N/A";
                            $obj->payment_mode = "N/A";
                            $obj->deposit = "N/A";
                            $obj->fine = "N/A";
                            $obj->balance = "N/A";
                            $obj->discount = "N/A";
                        }
                        $student_Array[] = $obj;
						}
                    }
                }


                $data['student_due_fee'] = $student_Array;
				$data['date_from2'] = $date_from;
				$data['date_to2'] = $date_to;
                // exit();
                $data['class_id'] = $class_id;
                $data['section_id'] = $section_id;
                $data['feetype'] = $feetype;
                $data['feetype_arr'] = $feetype_arr;
				
                $this->load->view('print/printBalanceFeesByGroup', $data);
            }
			
    function printTransactions() {


		        $setting_result = $this->setting_model->get();
                $data['settinglist'] = $setting_result;
				
                $data['title'] = 'Search Expense';

                $data['exp_title'] = 'Transaction From ' . $this->input->post('date_from') . " To " . $this->input->post('date_to');
                $date_from = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_from')));
                $date_to = date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('date_to')));
                $expenseList = $this->expense_model->search("", $date_from, $date_to);
                $incomeList = $this->income_model->search("", $date_from, $date_to);
                $feeList = $this->studentfeemaster_model->getFeeBetweenDate($date_from, $date_to);
                $data['expenseList'] = $expenseList;
                $data['incomeList'] = $incomeList;
                $data['feeList'] = $feeList;
                $data['date_from2'] = $date_from;
                $data['date_to2'] = $date_to;

            $this->load->view('print/printTransactions', $data);
    }		

}

?>