<?php
	class ExcelReport_model extends CI_model
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->database();
			//$this->db2 = $this->load->database('otherdb', TRUE);
	
		}

		public function getcatdata($branch_id){
			$query = $this->db->query("select I.item_id,I.category_id,C.category_name,I.item_name,I.uom from category C inner join item_creation I on C.category_id=I.category_id where I.branch_id='$branch_id' and I.status='Enabled' order by C.category_name,I.item_name");
			return $query->result();
		}
		
		public function getProductDetail($branch_id){
			$query = $this->db->query("select R.recipe_id,R.pr_cat_id,C.pr_cat_name,R.rname as product_name,R.uom from product_category C inner join recipe R on C.pr_cat_id=R.pr_cat_id where R.branch_id='$branch_id' and R.status='Enabled' order by C.pr_cat_name,R.rname");
			return $query->result();
		}

		public function stock_update($stk_id) {
			$query = $this->db->query("SELECT *,DATE_FORMAT(stk_date, '%d-%m-%Y') as stk_date FROM stock_update where stck_id='$stk_id'");
			return $query->result();
		}

		public function stk_update_items($stk_id) {
			$query = $this->db->query("SELECT * FROM  stock_update_item where stck_id='$stk_id'");
			return $query->result();
		}

		public function stock_update_list($branch_id) {
			$query = $this->db->query("SELECT *, DATE_FORMAT(stk_date, '%d-%m-%Y') as stk_date FROM stock_update where branch_id='$branch_id' and stock_no LIKE 'S%' ORDER BY stck_id desc");
			return $query->result();
		}
		
		public function daily_stock_update_list($branch_id) {
			$query = $this->db->query("SELECT *, DATE_FORMAT(stk_date, '%d-%m-%Y') as stk_date FROM stock_update where branch_id='$branch_id' and stock_no LIKE 'D%' ORDER BY stck_id desc");
			return $query->result();
		}

		public function stock_update_by_branch($data){
			$fdate =date('Y-m-d', strtotime($data['from_date']));
			$tdate =date('Y-m-d', strtotime($data['to_date']));
			$branch_id =$data['branch_id'] ;
			$query = $this->db->query("SELECT *, DATE_FORMAT(stk_date, '%d-%m-%Y') as stk_date FROM stock_update where stk_date between '$fdate' and '$tdate' and branch_id='$branch_id' and stock_no LIKE 'S%'");
			
			return $query->result();
		}
		
		public function getCounter($sub_mod_id,$branch_id)
		{
			$query = $this->db->query("SELECT * FROM user_access where branch_id='$branch_id' and module_id='$sub_mod_id'");
			return $query->result();	
		}
		
		public function fetchProduct($branch_id)
		{
			$query=$this->db->query("select * from recipe where branch_id='$branch_id' and status='Enabled'");
			$result = $query->result();
			return $result;
		}
	}
?>