<?php session_start();
if(empty($_SESSION['id'])):
header('Location:../index.php');
endif;

include('../dist/includes/dbcon.php');
$sid=$_REQUEST['sid'];
$cid=$_REQUEST['cid'];

		$query1=mysqli_query($con,"select * from sales where sales_id='$sid'")or die(mysqli_error($con));
		$row1=mysqli_fetch_array($query1);
		$mycustid=$row1['cust_id'];
	
	$query=mysqli_query($con,"select * from sales_details where sales_id='$sid'")or die(mysqli_error($con));
		while ($row=mysqli_fetch_array($query))
		{
			$pid=$row['prod_id'];	
 			$qty=$row['qty'];
			$price=$row['price'];
			$hh=$row['hh'];
			$ww=$row['ww'];
			$variation=$row['variation'];
			$color=$row['color'];
			$thicknew=$row['thick'];
			$mystatus=$row['status'];
			$branchpo=$row['branch'];
			
			mysqli_query($con,"INSERT INTO temp_trans(prod_id,cust_id,price,qty,branch_id,hh,ww,variation,color,disc,thick,discount,status) VALUES('$pid','$mycustid','$ww','$qty','$branchpo','$hh','$ww','$variation','$color','0','$thicknew','0','$mystatus')")or die(mysqli_error($con));
		}
	$result=mysqli_query($con,"DELETE FROM sales WHERE sales_id ='$sid'")or die(mysqli_error());
	$result=mysqli_query($con,"DELETE FROM payment WHERE sales_id ='$sid'")or die(mysqli_error());
	$result=mysqli_query($con,"DELETE FROM sales_details WHERE sales_id ='$sid'")or die(mysqli_error());
	echo "<script>document.location='cash_transaction1.php?cid=$cid&cat=1'</script>"; 
?>