<?php
class M_grafik extends CI_Model{

	function grafik_bulan(){
        date_default_timezone_set('Asia/Jakarta');
      
         $tahun = Date('Y');
        $bulan = Date('m');
         
        $query = $this->db->query("SELECT DAY(date) AS tanggal,SUM(harga_jual-harga_beli) AS jumlah FROM tb_jual_detail where   
          MONTH(date)='$bulan' and    YEAR(date)='$tahun'  
            GROUP BY DAY(date) order by tanggal asc");
         
        if($query->num_rows() > 0){
            foreach($query->result() as $data){
                $hasil[] = $data;
            }
            return $hasil;
        }
    }
    function grafik_tahun(){

         $tahun = Date('Y');
       
         
        $query = $this->db->query("SELECT MONTH(date) AS bulan,SUM(harga_jual-harga_beli) AS jumlah FROM tb_jual_detail  where   
             YEAR(date)='$tahun'  
            GROUP BY MONTH(date) order by bulan asc");
         
        if($query->num_rows() > 0){
            foreach($query->result() as $data){
                $hasil[] = $data;
            }
            return $hasil;
        }
    }
    public function graph()
    {
        date_default_timezone_set('Asia/Jakarta');
      
         $tahun = Date('Y');
        $bulan = Date('m');
        $data = $this->db->query("SELECT DAY(date) AS tanggal,SUM(((harga_jual-harga_beli)*jumlah))  AS jumlah FROM tb_jual_detail where   
          MONTH(date)='$bulan' and    YEAR(date)='$tahun'  
            GROUP BY DAY(date) order by tanggal asc");
        return $data->result();
    }
    public function graph2()
    {
        date_default_timezone_set('Asia/Jakarta');
      
         $tahun = Date('Y');
        $bulan = Date('m');
        $data = $this->db->query("SELECT MONTH(date) AS bulan,SUM(((harga_jual-harga_beli)*jumlah))  AS jumlah FROM tb_jual_detail where    YEAR(date)='$tahun'  
            GROUP BY MONTH(date) order by bulan asc");
        return $data->result();
    }

    // function grafik_bulan(){
    //     date_default_timezone_set('Asia/Jakarta');
      
    //      $tahun = Date('Y');
    //     $bulan = Date('m');
         
    //     $query = $this->db->query("SELECT DAY(date) AS tanggal,COUNT(*) AS jumlah FROM tb_transaksi where   
    //       MONTH(date)='01' and    YEAR(date)='$tahun'  
    //         GROUP BY DAY(date) order by tanggal asc");
         
    //     if($query->num_rows() > 0){
    //         foreach($query->result() as $data){
    //             $hasil[] = $data;
    //         }
    //         return $hasil;
    //     }
    // }
    // function grafik_tahun(){

    //      $tahun = Date('Y');
       
         
    //     $query = $this->db->query("SELECT MONTH(date) AS bulan,COUNT(*) AS jumlah FROM tb_transaksi where   
    //          YEAR(date)='$tahun'  
    //         GROUP BY MONTH(date) order by bulan asc");
         
    //     if($query->num_rows() > 0){
    //         foreach($query->result() as $data){
    //             $hasil[] = $data;
    //         }
    //         return $hasil;
    //     }
    // }

}