<?php
class HeadingMaster_model extends CI_Model {
function __construct()
	{
		parent::__construct();

	}
	public function get_headingMaster_list()
	{	//$searchtext, $column_name, $order_by
        $sql = "SELECT * FROM headingmaster where IsActive=0";
        $record = $this->db->query($sql);
        return $record->result_array();
	}	

public function save_headingMaster($post_data)
	{	
	
			$heading=$post_data['heading'];
				$sqlc = "SELECT count(*) as count,heading_no FROM headingmaster where IsActive=0 and heading='$heading'";
				$recordc = $this->db->query($sqlc);
				$cc=$recordc->row('count');
				$heading_no=$recordc->row('heading_no');
				if($cc > 0)
				{
				//	echo '131';
				$heading_no=$recordc->row('heading_no');
				}
				else
				{
				//	echo '22';
				$sql = "SELECT max(heading_no) as heading_no FROM headingmaster";
				$record = $this->db->query($sql);
				$heading_no1=$record->row('heading_no');
				$heading_no=$heading_no1+1;				
				}
				
	
	
				$count2 = count($post_data['master_product']);
			//echo $count2;
				$query_values2 = array();

				for($i=0; $i<$count2; $i++)
				{
				//	echo $i;
				$db = get_instance()->db->conn_id;

				
				$master_product=mysqli_real_escape_string($db,$post_data['master_product'][$i]);
				$heading=$post_data['heading'];
				
				$data=array('heading'=>$heading,'master_product'=>$master_product,'heading_no'=>$heading_no);
				$in=$this->db->insert('headingmaster',$data);
				}
				return TRUE;
				
	}	


		public function update_headingMaster($post_data)
	{	
				
							$heading_no=$post_data['id'];

				$this->db->where('heading_no',$heading_no);
				 $in= $this->db->delete('headingmaster');
				 
				$count2 = count($post_data['master_product']);
			//echo $count2;
		
				$query_values2 = array();

				for($i=0; $i<$count2; $i++)
				{
				//	echo $i;
				$db = get_instance()->db->conn_id;

				
				$master_product=mysqli_real_escape_string($db,$post_data['master_product'][$i]);
				
				$heading=$post_data['heading'];
				$heading_no=$post_data['id'];
			//	$order=$post_data['order'];
			//	$master_product=$post_data['master_product'];
				
				
				 
			$data=array('heading'=>$heading,'master_product'=>$master_product,'heading_no'=>$heading_no);

				$in=$this->db->insert('headingmaster',$data);
				}
			//	exit;
				return TRUE;
				
	}	

	public function delete_headingMaster($id)
	{	
	
				$data=array('IsActive'=>'1');
				$this->db->where('heading_no',$id);
				 return $this->db->update('headingmaster',$data);
			
				
	}	

	public function get_master_product_list()
	{	//$searchtext, $column_name, $order_by
        $sql = "SELECT * FROM product where IsActive=0";
        $record = $this->db->query($sql);
        return $record->result_array();
	}	


}?>