<?php

include('db_connection.php');

$Mainclass=new DB_Controller();

$Order_Id=$_REQUEST['Order_No'];



$SqCheckIndent="select * from gold_indent_master where Order_No='".$Order_Id."'";
$RsCheckIndent=mysqli_query($Mainclass->dbh,$SqCheckIndent);
$FchIndent=mysqli_fetch_array($RsCheckIndent);







	$FieldValue1="Status='Cancel'";

	$Condition1=" Order_No='".$Order_Id."'";

	$Up_order_master=$Mainclass->Update_Data('gold_indent_master',$FieldValue1,$Condition1);

	
     $condition="Order_No='".$Order_Id."'";
	 $condition.=" order by Product_Code";
     $Get_Dealers_Stock=$Mainclass->Fetch_multiple_data('gold_indent_details','*',$condition);   
	 foreach($Get_Dealers_Stock as $stock)
	{

		
		 $UpdateProductStock = "UPDATE gold_products_master 
                           SET Stock = Stock + " . intval($stock['Order_Quantity']) . " 
                           WHERE Productid = '" . mysqli_real_escape_string($Mainclass->dbh, $stock['Product_Code']) ."'";
						   mysqli_query($Mainclass->dbh,$UpdateProductStock);
						   
						   
						   $SqlDelChallanDtls="delete from gold_challan_details where Challan_No='".$FchIndent['STN_NO']."'";
		                   mysqli_query($Mainclass->dbh,$SqlDelChallanDtls);
						   
						   $SqlDelChallanDtls="delete from  gold_challan_master where Challan_No='".$FchIndent['STN_NO']."'";
		                   mysqli_query($Mainclass->dbh,$SqlDelChallanDtls);
	}


?>