<?php

	require_once 'dbconfig.php';
	require_once 'conn.php';

	if(isset($_GET['order_id']))
	{

		$stmt_delete = $DB_con->prepare('DELETE FROM mobileorders WHERE order_id =:order_id');
		$stmt_delete->bindParam(':order_id',$_GET['order_id']);
		$stmt_delete->execute();
		$oid = $_GET['order_id'];
		$tempcart = mysqli_query($conn, "SELECT * FROM mobiletemporarycart WHERE orderid='$oid'");
		if ($tempcart->num_rows > 0) {
			while($row = $tempcart->fetch_assoc()) {
				$proid = $row['proid'];
				$qty = $row['pro_qty'];

				$sql = "UPDATE tbl_stock SET qty=qty+'$qty' WHERE prid='$proid'";
				if ($conn->query($sql) === TRUE) {

				}
			}
		}


		$stmt_delete = $DB_con->prepare('DELETE FROM mobiletemporarycart WHERE orderid =:order_id');
		$stmt_delete->bindParam(':order_id',$_GET['order_id']);
		$stmt_delete->execute();
		
		$stmt_delete = $DB_con->prepare('DELETE FROM invoice_other_details WHERE order_id =:order_id');
		$stmt_delete->bindParam(':order_id',$_GET['order_id']);
		$stmt_delete->execute();
		
		//header("Location: services.php");
		echo"<script type='text/javascript'>window.location.href = 'saleslist.php';</script>";
		
	}

?>