<?php
include 'inc_classes.php';
$action=$_POST['action'];

if($action=='get_checkout_product')
{
	$branch_name=$_POST['branch_name'];
	$totals=$_POST['totals'];
	if($branch_name!='')
	{
		$sql_cm="select cm_id,admin_id,name from site_setting where branch_name='".$branch_name."' and type='ST' and system_status='Enabled' ";
		$ptr_cm= mysql_query($sql_cm);
		$data_cm=mysql_fetch_array($ptr_cm);
		
		$select_product_name="select product_id,product_name,quantity,admin_id from product where 1 and quantity>0 and  cm_id='".$data_cm['cm_id']."' and admin_id='".$data_cm['admin_id']."' and status='Active' "; 
		$query_product=mysql_query($select_product_name);
		if(mysql_num_rows($query_product))
		{
			$name='';
			while($fetch_array=mysql_fetch_array($query_product))
			{
				$sel_emp="select name from site_setting where admin_id='".$fetch_array['admin_id']."'";
				$ptr_admin_id=mysql_query($sel_emp);
				$data_name=mysql_fetch_array($ptr_admin_id);
				$name= "(".$data_name['name'].")";
				echo "<option value='".$fetch_array['product_id']."' >".addslashes($fetch_array['product_name'])." (Qty- ".$fetch_array['quantity'].")&nbsp;&nbsp;&nbsp;".$name."</option>";
			}
		}
	}
}
else if($action=='get_category_wise_product')
{
	$branch_name=$_POST['branch_name'];
	$totals=$_POST['totals'];
	$cat_id=$_POST['cat_id'];
	if($cat_id!='')
	{
		$sql_cm="select cm_id,admin_id,name from site_setting where branch_name='".$branch_name."' and type='ST' and system_status='Enabled' ";
		$ptr_cm= mysql_query($sql_cm);
		$data_cm=mysql_fetch_array($ptr_cm);
		
		$select_product_name="select product_id,product_name,quantity,admin_id from product where 1 and cm_id='".$data_cm['cm_id']."' and admin_id='".$data_cm['admin_id']."' and status='Active' and pcategory_id='".$cat_id."' "; 
		$query_product=mysql_query($select_product_name);
		if(mysql_num_rows($query_product))
		{
			$name='';
			while($fetch_array=mysql_fetch_array($query_product))
			{
				$sel_emp="select name from site_setting where admin_id='".$fetch_array['admin_id']."'";
				$ptr_admin_id=mysql_query($sel_emp);
				$data_name=mysql_fetch_array($ptr_admin_id);
				$name= "(".$data_name['name'].")";
				echo "<option value='".$fetch_array['product_id']."' >".addslashes($fetch_array['product_name'])." -&nbsp;&nbsp;&nbsp;".$name."</option>";
			}
		}
	}
}
else if($action=='get_product_category')
{
	$branch_name=$_POST['branch_name'];
	if($branch_name!='')
	{
		$sql_cm="select cm_id,admin_id,name from site_setting where branch_name='".$branch_name."' and type='ST' and system_status='Enabled' ";
		$ptr_cm= mysql_query($sql_cm);
		$data_cm=mysql_fetch_array($ptr_cm);
		
		$sel_domain="SELECT * FROM product_category where 1 and cm_id='".$data_cm['cm_id']."' order by pcategory_id asc ";	 
		$query_domain=mysql_query($sel_domain);
		$total_d=mysql_num_rows($query_domain);
		echo '<table width="100%"><tr><td>'; 
		echo '<select id="cat_id" name="cat_id" onChange="get_product_by_cat(this.value)">';
		echo '<option value="">Select Product Category</option>';
		while($data_domain=mysql_fetch_array($query_domain))
		{
			$sl_name="select admin_id,name from site_setting where system_status='Enabled' and type='ST' and cm_id='".$data_cm['cm_id']."'"; 
			$ptr_name=mysql_query($sl_name);
			$data_fname=mysql_fetch_array($ptr_name);
			echo '<option value="'.$data_domain['pcategory_id'].'">'.$data_domain['pcategory_name'].' - ('.$data_fname['name'].')</option>';
		}
		echo '</select>';
		echo "</td></tr></table>";
	}
}
else if($action=='get_order_list')
{
	$branch_name=$_POST['branch_name'];
	if($branch_name!='')
	{
		$sql_cm="select cm_id,admin_id,name from site_setting where branch_name='".$branch_name."' and type='A' ";
		$ptr_cm= mysql_query($sql_cm);
		$data_cm=mysql_fetch_array($ptr_cm);
		
		echo'<select name="order_id" id="order_id" class="input_select_login" style="width:150px;">
		<option value="">Select Order No.</option>';
		$sel_order="select * from order_list where 1 and cm_id='".$data_cm['cm_id']."' order by order_list_id desc ";
		$ptr_order=mysql_query($sel_order);
		while($data_order=mysql_fetch_array($ptr_order))
		{
			$sel='';
			if($data_order['order_no']==$_GET['order_no'])
			{
				$sel='selected="selected"';
			}
			$sl_name="select admin_id,name from site_setting where admin_id='".$data_order['employee_id']."'"; 
			$ptr_name=mysql_query($sl_name);
			$data_fname=mysql_fetch_array($ptr_name);
			echo '<option '.$sel.' value="'.$data_order['order_list_id'].'" > '.$data_order['order_no'].' - '.$data_fname['name'].'</option>';
		}
		echo '</select>';
	}
}
else if($action=='get_sales_product')
{
	$branch_name=$_POST['branch_name'];
	$totals=$_POST['totals'];
	if($branch_name!='')
	{
		$sql_cm="select cm_id,admin_id,name from site_setting where branch_name='".$branch_name."' and type='ST' and system_status='Enabled' ";
		$ptr_cm= mysql_query($sql_cm);
		$data_cm=mysql_fetch_array($ptr_cm);
		
		$sel_tel="select p.product_id,p.product_name,p.price,p.quantity,p.admin_id from product p, site_setting s where 1 and p.status='Active' and p.admin_id=s.admin_id and p.cm_id='".$data_cm['cm_id']."' and p.admin_id='".$data_cm['admin_id']."' and p.quantity > 0  order by product_id asc";
		$query_tel = mysql_query($sel_tel);
		while($data=mysql_fetch_array($query_tel))
		{
			$name='';
			$sel_emp="select name from site_setting where admin_id='".$data['admin_id']."'";
			$ptr_admin_id=mysql_query($sel_emp);
			$data_name=mysql_fetch_array($ptr_admin_id);
			$name= "(".$data_name['name'].")";
			echo '<option value="'.$data['product_id'].'">'.addslashes($data['product_name']).'&nbsp;&nbsp;(Price - '.addslashes($data['price']).')&nbsp;&nbsp;'.$name.'</option>';
		}
	}
}
else
{
	$vendor_id=$_POST['vendor_id'];
	$totals=$_POST['totals'];
	if($_POST['vendor_id']!='')
	{
		$sql_dest = " select product_id, vendor_id from product_vendor_map where vendor_id='".$vendor_id."' ";
		$ptr_edes = mysql_query($sql_dest);
		if(mysql_num_rows($ptr_edes))
		{
			while($data_dist = mysql_fetch_array($ptr_edes))
			{
				//for($i=1;$i<=$totals;$i++)
					//{
				$select_product_name="select product_id,product_name,quantity,admin_id from product where product_id='".$data_dist['product_id']."' and status='Active' ".$_SESSION['where']." "; //".$_SESSION['user_id']." on 13/6/18
				$query_product=mysql_query($select_product_name);
				if(mysql_num_rows($query_product))
				{
					$fetch_array=mysql_fetch_array($query_product);
					
					$name='';
					//if($_SESSION['type'] =='S')
					//{
						$sel_emp="select name from site_setting where admin_id='".$fetch_array['admin_id']."'";
						$ptr_admin_id=mysql_query($sel_emp);
						$data_name=mysql_fetch_array($ptr_admin_id);
						
						$name= "(".$data_name['name'].")";
					//}
					
					echo "<option value='".$fetch_array['product_id']."' >".addslashes($fetch_array['product_name'])." (Qty- ".$fetch_array['quantity'].")&nbsp;&nbsp;&nbsp;".$name."</option>";
				}
			}
		}
	}
}
?>