<?php
include('db_connection.php');
$Mainclass=new DB_Controller();
$Barcode=$_REQUEST['pro_id'];
$Product_Id=substr($_REQUEST['pro_id'],0,-4);
$Order_Id=$_REQUEST['order'];

//=======Check Product Exist In Gold Product Master======// 
$Check_Product=$Mainclass->num_check("gold_products_master","SLN","Productid='".$Product_Id."' and Active='Yes'");

if($Check_Product>0)
{
	$Condition=" Product_Code ='".$Product_Id."' and Dealer_Code='".$_COOKIE['O_Code']."'";
    $Get_Quantity=$Mainclass->Fetch_individual_data('dealer_gold_stock_master',"Quantity,Booked,DRP",$Condition);
			
	if($Order_Id!='')
	{
	$Condition_Det_pro=$Condition." and Order_No='".$Order_Id."'";
	$Get_added_Quantity=$Mainclass->Fetch_individual_data('gold_billing_order_details',"Quantity",$Condition_Det_pro);
		$Order_Stock=$Get_added_Quantity['Quantity'];
	}

	else
	{
		$Order_Stock="0";
	}

			
	$SaleQty=$Get_Quantity['Quantity'] - $Get_Quantity['Booked'] - $Get_Quantity['DRP'] - $Order_Stock;
   
    if($SaleQty>0)   
    {
    $Error="0";
    $pid=$Product_Id;   
	}   

	else
	{         
	  $Error="2";  //=====No Stock=====// 
	}
}

else
{
	$Error=1;//====Product Not In Product Master=====//
}

echo $Error."*".$pid."*".$Barcode;
?>