<?php
include('db_connection.php');
$Mainclass=new DB_Controller();

$Order_No=$_REQUEST['Order_No'];


$SqlIndDtlUp="update gold_indent_details set Del_Ind='0' where Order_No='".$Order_No."'";
mysqli_query($Mainclass->dbh,$SqlIndDtlUp);

$condition.="  Order_No='".$Order_No."' order by SLN desc";
//$GetIndentDtl=$Mainclass->Challan_det_return('indent_details',$condition);
$GetIndentDtl=$Mainclass->Fetch_distinct_datas('gold_indent_details','Product_Code',$condition);
$StockOutProduct="";
foreach($GetIndentDtl as $IndentDtl)
{
	
	
	//$PMSDCondition=" Product_Code ='".$IndentDtl['Product_Code']."'"; 
	 
	//$PMSD_QTY=$Mainclass->Challan_Details('product_master',$PMSDCondition);
	
	$PMSD_QTY=$Mainclass->product_det('gold_products_master',$IndentDtl['Product_Code']);
	
	
	$IndDtlCondition=" Product_Code ='".$IndentDtl['Product_Code']."' and Order_No='".$Order_No."'"; 
	
	//$IndOrderQty=$Mainclass->Fetch_needed_data_condition('indent_details','sum(Order_Quantity) as Order_Quantity',$IndDtlCondition);
	
	$IndOrderQty=$Mainclass->Fetch_individual_data('gold_indent_details','sum(Order_Quantity) as Order_Quantity',$IndDtlCondition);
	
	$IndOrderProQty=$IndOrderQty['Order_Quantity'];
	
	
	
	 $WHStock=$PMSD_QTY['Stock'];
	
	if($WHStock<$IndOrderProQty)
	{
	   //echo "Stock Out";
	    //exit;
		
		 $diffStcokLimit=($IndOrderProQty-$WHStock);
		
		$StockOutProduct=$StockOutProduct.",".$IndentDtl['Product_Code'];
		 
		$SqlIndUp="update gold_indent_details set Del_Ind='1' where Order_No='".$Order_No."' and Product_Code='".$IndentDtl['Product_Code']."' order by SLN desc limit ".$diffStcokLimit;
		$rs=mysqli_query($Mainclass->dbh,$SqlIndUp);
	
	}
}
if(strlen($StockOutProduct)>0)
{	
  echo $StockOutProduct=ltrim($StockOutProduct,",");
}
//$arrayProduct = explode(',', $StockOutProduct);
//$StockOutCount=count($arrayProduct);

/*foreach($arrayProduct as $StockOutProductCode)
{
    echo $StockOutProductCode;
}*/
?>