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

class Lap_Penjualan_Terlaris extends CI_Controller {

	/**
	 * @keterangan : Controller untuk halaman profil
	 **/
	
	public function index()
	{
		$cek = $this->session->userdata('logged_in');
		if(!empty($cek)){
			
			$d['prg']= $this->config->item('prg');
			$d['web_prg']= $this->config->item('web_prg');
			
			$d['nama_program']= $this->config->item('nama_program');
			$d['instansi']= $this->config->item('instansi');
			$d['usaha']= $this->config->item('usaha');
			$d['alamat_instansi']= $this->config->item('alamat_instansi');

			$d['judul']="Laporan Penjualan Terlaris";
			
			$d['content'] = $this->load->view('lap_penjualan_terlaris/form', $d, true);		
			$this->load->view('home',$d);
		}else{
			header('location:'.base_url());
		}
	}
	
	public function lihat()
	{
		$cek = $this->session->userdata('logged_in');
		if(!empty($cek)){
			$tgl1 		= $this->app_model->tgl_sql($this->input->post('tgl1'));
			$tgl2 		= $this->app_model->tgl_sql($this->input->post('tgl2'));
			$kunjungan 	= $this->input->post('kunjungan');
			$instalasi	= $this->input->post('instalasi');
			
			$where = " WHERE tgljual BETWEEN '$tgl1' AND '$tgl2'";
			
			$text = "SELECT DISTINCT(kode_barang),nama_barang,
                    COUNT(kode_barang) AS jml
                        FROM
	                        vwdetail_jual
                    $where
                    GROUP BY kode_barang
                    ORDER BY
	                    jml DESC
                    LIMIT 100";
			$d['data'] = $this->app_model->manualQuery($text);
			
			$this->load->view('lap_penjualan_terlaris/view',$d);
		}else{
			header('location:'.base_url());
		}
	}
	
	public function cetak()
	{
		$cek = $this->session->userdata('logged_in');
		if(!empty($cek)){
			
			$d['prg']= $this->config->item('prg');
			$d['web_prg']= $this->config->item('web_prg');
			
			$d['nama_program']= $this->config->item('nama_program');
			$d['instansi']= $this->config->item('instansi');
			$d['usaha']= $this->config->item('usaha');
			$d['alamat_instansi']= $this->config->item('alamat_instansi');
			$d['judul']="Laporan Penjualan Terlaris";
			
		
			$tgl1 = $this->app_model->tgl_sql($this->uri->segment(3));
			$tgl2 = $this->app_model->tgl_sql($this->uri->segment(4));
			
			$d['filter'] = $this->app_model->tgl_indo($tgl1).' s.d '.$this->app_model->tgl_indo($tgl2);	
			$where = " WHERE tgljual BETWEEN '$tgl1' AND '$tgl2' ";
			
			$text = "SELECT DISTINCT(kode_barang),nama_barang,
                    COUNT(kode_barang) AS jml
                        FROM
	                        vwdetail_jual
                    $where
                    GROUP BY kode_barang
                    ORDER BY
	                    jml DESC
                    LIMIT 100";
			$d['data'] = $this->app_model->manualQuery($text);
			
			$this->load->view('lap_penjualan_terlaris/cetak',$d);
		}else{
			header('location:'.base_url());
		}
	}

}

/* End of file profil.php */
/* Location: ./application/controllers/profil.php */