<?php

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

class Dashboard_controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        // Your own constructor code
       
        if($this->session->userdata('role')==''){
            redirect('logout');
        }
    }


    public function index(){
        ///get all branches
        $sql = "select 
                SUM(invoice.paid_cash) paid_cash, 
                SUM(invoice.paid_card) paid_card, 
                SUM(case when invoice.instrument_number like 'Online%' then invoice.paid_check else 0 end) as 'Online',
                SUM(case when invoice.instrument_number not like 'Online%' then invoice.paid_check else 0 end) as 'Check',    
                SUM(invoice.paid_check),     
                business.id_business, business.business_name 
                FROM business 
                LEFT JOIN invoice on invoice.business_id = business.id_business
                WHERE common_products = 'Yes' 
                AND invoice.invoice_status = 'valid'
                GROUP BY id_busines
        ";
        $query = $this->db->query($sql);

        $invoices = $query->result_array();




    }


}