<?php 

class M_stokopname extends CI_Model{
	public function __construct()
	{
		$this->load->database();
	}
	 


	function laporan($jenis_laporan,$tanggal, $id_kantor_cari,$bulan,$tahun,	$tanggal_awal,	$tanggal_akhir,$id_admin){

		if($jenis_laporan =='harian'){
			if($id_kantor_cari == 'all'){
				$query = $this->db->query("select  *  from tb_stok_opname where date(tb_stok_opname.date) = '$tanggal'   order by tb_stok_opname.date desc ");
			}else{
				$query = $this->db->query("select  * from tb_stok_opname where date(tb_stok_opname.date) = '$tanggal' and tb_stok_opname.id_kantor ='$id_kantor_cari' order by tb_stok_opname.date desc ");
			}

		}else  if($jenis_laporan =='bulanan'){
			if($id_kantor_cari == 'all'){
				 $query = $this->db->query("select  * from tb_stok_opname where month(tb_stok_opname.date)='$bulan' and year(tb_stok_opname.date)='$tahun'  order by tb_stok_opname.date desc ");
			}else{
				 $query = $this->db->query("select  * from tb_stok_opname where month(tb_stok_opname.date)='$bulan' and year(tb_stok_opname.date)='$tahun' and tb_stok_opname.id_kantor ='$id_kantor_cari' order by tb_stok_opname.date desc ");
			}
				
		}else  if($jenis_laporan =='pilihan'){
			if($id_kantor_cari == 'all'){
				 	$query = $this->db->query("select  * from tb_stok_opname where  tb_stok_opname.date BETWEEN '$tanggal_awal' AND '$tanggal_akhir'   order by tb_stok_opname.date desc ");
			}else{
				 	$query = $this->db->query("select  * from tb_stok_opname  where tb_stok_opname.id_kantor ='$id_kantor_cari'and tb_stok_opname.date BETWEEN '$tanggal_awal' AND '$tanggal_akhir'   order by tb_stok_opname.date desc ");
			}
		
		}else  if($jenis_laporan =='kasir'){
			if($id_kantor_cari == 'all'){
				$query = $this->db->query("select  *  from tb_stok_opname where date(tb_stok_opname.date) = '$tanggal' and tb_stok_opname.id_admin ='$id_admin'   order by tb_stok_opname.date desc ");
			}else{
				$query = $this->db->query("select  * from tb_stok_opname where date(tb_stok_opname.date) = '$tanggal' and tb_stok_opname.id_kantor ='$id_kantor_cari' and tb_stok_opname.id_admin ='$id_admin' order by tb_stok_opname.date desc ");
			}
		
		}

        return $query->result();
    } 
   
   
 
	  
}