<?php

	$id = $_REQUEST['id'];
	include("../config.php");
	

		$qry1 = mysqli_query($db,"SELECT * FROM tbl_purchaseitems WHERE id = $id AND status = 3 ");
		$row = mysqli_fetch_array($qry1);
		$avl = $row['aval'];
		if(round($avl) == 0){
			$sql = "DELETE FROM tbl_purchaseitems WHERE id = $id AND status = 3";
			if(mysqli_query($db,$sql)){
				echo 'ok';
			} else {
				mysqli_error($db);
			}
		} else {
			$sql = "UPDATE tbl_purchaseitems SET last_qty = NULL,status = 1 WHERE id = $id AND status = 3";
			if(mysqli_query($db,$sql)){
				echo 'ok';
			} else {
				mysqli_error($db);
			}
		}


	// $id = $_REQUEST['id'];
	// include("../config.php");
	// $sql = "DELETE FROM tbl_purchaseitems WHERE id = $id AND status = 3";
	// if(mysqli_query($db,$sql))
	// 	echo 'ok';
	// else
	// 	mysqli_error($db);
?>
