<?php

class Manual_Query_With_Grn_Model extends CI_Model {

  function __construct()
  {
    /* Call the Model constructor */
    parent::__construct();
     $this->db->query("SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));");
  }
	function get_all_data() {
		$this->db->select('t.*');
		$this->db->from('temp_s_with_grn t');
		//$this->db->order_by("t.id", "desc");
		//$this->db->where("t.category",$val);//("id !=",$id);
		$query = $this->db->get();
		//echo $this->db->last_query();
		return $query->result_array();
	}



	function save_data($supplier_data)
	{
			$this->db->insert('product',$supplier_data);
			//echo $this->db->last_query();
	}


    	function get_all_product_data() {
		$this->db->select('t.product_id,t.product_name,t.product_code,t.product_cost');
		$this->db->from('product t');
		$query = $this->db->get();
		return $query->result_array();
	}
	
	 public function getSoldqty($id)
    {
        $this->db->select_sum('si.quantity');
        $this->db->from('sale_items si');  
        $this->db->where("si.product_id",$id);
        $query = $this->db->get();
        return $query->row()->quantity;
    }

    function duplicate_sale_list($id='')
    {
       
        $this->db->select('count(*) as cnt');
        	$this->db->select('sale_id,uniq_id');
        $this->db->group_by(array("uniq_id"));
        $this->db->having("cnt > 1", null, false);
        $this->db->limit(10000);
        $q= $this->db->get("sales");
        return $q->result();

    }
    
     function duplicate_sale_list2(){
        $this->db->select('t.sale_id');
		$this->db->from('sales t');
		$this->db->where("uniq_id",null);
		$query = $this->db->get();
		return $query->result();
        
    }
    
    function update_sale_master($id,$data){
        if($id>0){
         $this->db->where("sale_id",$id);
        $query = $this->db->update('sales',$data);
        }
    }


}